Union C++ standard

Hans-Peter Diettrich <DrDiettrich1@netscape.net>
Thu, 25 Nov 2021 11:11:04 +0100

          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)
[7 later articles]
| List of all articles for this month |
From: Hans-Peter Diettrich <DrDiettrich1@netscape.net>
Newsgroups: comp.compilers
Date: Thu, 25 Nov 2021 11:11:04 +0100
Organization: Compilers Central
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="44177"; mail-complaints-to="abuse@iecc.com"
Keywords: C, standards
Posted-Date: 26 Nov 2021 12:31:56 EST

Can somebody explain why the access to members of a union is "undefined"
except for the most recently written member?


What can be undefined in a union of data types of the same typesize end
alignment? Any member written will result in a unique bit/byte pattern
in memory, whose reading may not make sense in a different type but
undoubtedly is well defined.


DoDi
[I think it's undefined in a standards sense. In any individual
implementation the result is predictable, but it's not portable. -John]



Post a followup to this message

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