Question about unions

Karl Heuer karl at haddock.ISC.COM
Sat May 28 08:56:33 AEST 1988


In article <16490002 at hpcllz2.HP.COM> walter at hpcllz2.HP.COM (Walter Murray) writes:
>[The dpANS mentions that there may be padding at the end of a structure.]
>Is there any reason a similar statement is not made about unions?
>Section 3.3.3.4 (the sizeof operator) certainly implies that a
>union may have padding.

I don't agree that 3.3.3.4 implies it, but I think that it does have to be
allowed.  The existence of pointers to incomplete types requires that a
word-addressible machine use a consistent format for pointer-to-union
(likewise for pointer-to-struct; this has been expressed as "all struct
pointers smell the same"), and I believe the usual choice for this is word
pointers -- which means that union{char} contains trailing padding.  Looks
like 3.5.2.1 should be reworded to mention unions.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.std.c mailing list