Re: Union C++ standard

Derek Jones <derek@NOSPAM-knosof.co.uk>
Mon, 29 Nov 2021 00:09:39 +0000

          From comp.compilers

Related articles
Union C++ standard DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2021-11-25)
Re: Union C++ standard 480-992-1380@kylheku.com (Kaz Kylheku) (2021-11-26)
Re: Union C++ standard gah4@u.washington.edu (gah4) (2021-11-26)
Re: Union C++ standard david.brown@hesbynett.no (David Brown) (2021-11-27)
Re: Union C++ standard derek@NOSPAM-knosof.co.uk (Derek Jones) (2021-11-28)
Re: Union C++ standard david.brown@hesbynett.no (David Brown) (2021-11-28)
Re: Union C++ standard derek@NOSPAM-knosof.co.uk (Derek Jones) (2021-11-29)
Re: Union C++ standard 480-992-1380@kylheku.com (Kaz Kylheku) (2021-11-29)
Re: Union C++ standard david.brown@hesbynett.no (David Brown) (2021-11-29)
Re: Union C++ standard Keith.S.Thompson+u@gmail.com (Keith Thompson) (2021-11-29)
Re: Union C++ standard derek@NOSPAM-knosof.co.uk (Derek Jones) (2021-11-30)
Re: Union C++ standard gneuner2@comcast.net (George Neuner) (2021-11-30)
Re: Union C++ standard david.brown@hesbynett.no (David Brown) (2021-11-30)
[1 later articles]
| List of all articles for this month |

From: Derek Jones <derek@NOSPAM-knosof.co.uk>
Newsgroups: comp.compilers
Date: Mon, 29 Nov 2021 00:09:39 +0000
Organization: Compilers Central
References: 21-11-004 21-11-008 21-11-009 21-11-010
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="99482"; mail-complaints-to="abuse@iecc.com"
Keywords: C, standards
Posted-Date: 28 Nov 2021 22:18:40 EST
In-Reply-To: 21-11-010
Content-Language: en-US

David,


>>> In C, type-punning via unions is allowed (i.e., fully defined behaviour
>>
>> That is not true.  Writing into one member and then reading from
>> another member is undefined behavior.
>
> No, it is correct. It would be helpful if you looked at the full


You have misunderstood the C conformance model, which revolves around
the use of "shall" and "shall not", and the kind of section in which
they appear (e.g., Constraints). See:
http://c0x.shape-of-code.com/4..html


For a longer discussion see: http://knosof.co.uk/cbook/


> """
> If the member used to read the contents of a union object is not the
> same as the member last used to store a value in the object, the
> appropriate part of the object representation of the value is
> reinterpreted as an object representation in the new type as described
> in 6.2.6 (a process sometimes called "type punning"). This might be a
> trap representation.
> """
>
> These quotations are from C18 (draft N2346), which is the current C
> standard (until C23 is finalised). They have not changed since C99,


This footnote was added in response to this DR (so it must have come
after C99):
http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_283.htm


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.