[comp.lang.c] overlap of union members

evil@arcturus.UUCP (Wade Guthrie) (11/28/89)

I'm still trying to understand the way in which ANSI union member overlap differs
from that described in K&R (I) in which each of the members have zero offset from
the union address.  If I understand the reason for the relaxation of this requirement,
it is due to (potential) alignment problems of the types of the members of the union.
If this is the case and a particular union is not allocated at a maximally (for the
types of the union's members) aligned location, then padding must be inserted in
order for the members to be within their proper respective alignment restrictions.

QUESTION 1: Is the above a fair description of the differences?

QUESTION 2: If a union is malloced or calloced (both of which, I believe, return
maximally aligned pointers), would all of the members have zero offset under the
ANSI requirements?

QUESTION 3: Does some way exist (other than that specified in QUEST 2, if the
answer there is "yes") to force the members to have zero offset, or to force the
union to be at a maximally aligned address?

Thanx.


Wade Guthrie
evil@arcturus.UUCP
Rockwell International
Anaheim, CA

(Rockwell doesn't necessarily believe / stand by what I'm saying; how could
they when *I* don't even know what I'm talking about???)