Re: I hate
Adam Megacz <[email protected]> Fri, 14 May 2004 01:33:33 -0700
| Newsgroups | gmane.comp.java.xwt.core |
|---|---|
| Organization | XWT |
| Message-ID | <[email protected]> |
Or it can insert empty space between consecutive members of a struct (think union-of-structs) to improve data alignment. - a Brian Alliet <[email protected]> writes: > On May 13, 2004, at 9:25 AM, Andrew Kohlsmith wrote: > >> ... Why shouldn't it work? I don't know Pascal but I was under the >> impression >> that was the *specific* reason for unions in C. > > Say that in comp.lang.c and you'll get yourself killed :) (check the > archives in google, they're vicious in there). > >> union { >> short s1; >> int i1; >> long l1; } mystuff; >> >> mystuff.l1 = 0xffffffff; >> mystuff.i1 = 0xaaaa; >> mystuff.s1 = 0x00; >> >> mystuff.l1 should now be 0xffffaa00, should it not? > > Certainly not. For all you know sizeof(short) == sizeof(int) == > sizeof(long). Even if they aren't you don't know what endianness the > target platform is. And even if you know all that. The compiler can > perfectly legally treat the above as just a plain old struct and not > have the memory overlapping at all! > > -Brian > > > _______________________________________________ > core mailing list > [email protected] > http://lists.xwt.org/listinfo/core > -- "Truth is One, though the Sages know it as Many." -- Rig Veda