Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: Union element alignment query Message-ID: <516@taumet.com> Date: 17 Nov 90 23:59:19 GMT References: <810001@hplred.HP.COM> Organization: Taumetric Corporation, San Diego Lines: 25 curry@hplred.HP.COM (Bo Curry) writes: !union { ! FOOTYPE a[4]; ! BARTYPE b; !} combo; !Does the standard guarantee that (void *)(&combo.a[0]) == (void *)(&combo.b) ? Not exactly. The standard (section 3.5.2.1) requires that (FOOTYPE*)&combo == &combo.a[0] and that (BARTYPE*)&combo == &combo.b There is also a requirement that given a type T, and the declaration T* t; then (T*)(void*)t == t; I don't believe that there is any requirement that the relation you specify must hold. On machines where pointers to different types may have different sizes, their conversions to void* might not be equal. The standard only requires that conversion from void* back to the original pointer type must work. -- Steve Clamage, TauMetric Corp, steve@taumet.com