Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. COMy understanding is that we should think of unions as a variant type and only the member which has been written the more recently can be read and type punning with union is undefined behavior. (The special rules allowing to inspect the common prefix of structures in an union would be without object if it wasn't the case. I'm pretty sure I've already read better references in the standard than that but I can't find them now.)
      singulars
    2. COWell, subverting the type system is always undefined behavior, but it's also sometimes just plain necessary when you are trying to do some platform specific things (like fiddling the sign bits of floats). One of the changes from C90 to C99 was to remove any restriction on accessing one member of a union when the last store was to a different one. Embedded programmers often have to do things that make language purists scream.
      singulars
    3. COThere is a difference between C++ and C here and I answered in the context of C++. First what is common: in both cases assigning to a member makes the bytes unused by this member undefined (it is very clear in C, 6.2.6.1/7 in N1124) and I think the compiler can assume that what it wrote is still there (but I didn't find a statement as clear). What isn't common, in C reading another member than the last written was implementation defined and now got somewhat defined. As far as I know, in C++ it is undefined (at least I didn't find anything hinting otherwise, I'm interested if you know some).
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload