Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Bit-field union bug |
| Date | 2012-01-24 12:23 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <kfnd3a8hmt7.fsf@x-alumni2.alumni.caltech.edu> (permalink) |
| References | (1 earlier) <ln62ldtgdq.fsf@nuthaus.mib.org> <j3ttr8$uil$1@speranza.aioe.org> <9cfgfeFsstU3@mid.individual.net> <j3u573$h5b$1@speranza.aioe.org> <0.d9fab49de2f78c213571.20110903223032BST.87zkil5n5z.fsf@bsb.me.uk> |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Quentin Pope <qp19433@hotmail.NOSPAM.com> writes:
>
>> [snip]
>>
>> For example, imagine
>> struct foo {
>> unsigned short a:2;
>> unsigned short b:2;
>> unsigned short c:2;
>> unsigned short d:2;
>> };
>>
>> If sizeOf(foo) is 3, then there is no way of telling whether a and b are
>> packed into 1 byte, or if it's b and c, or if it's c and d.
>
> [snip]
>
> In the "unsigned int" version, the C standard says that a, b, c and d
> must be packed together, consecutively, in the first byte of the struct.
> The "addressable storage unit" into which they get packed can't be less
> than 1 byte in size and a byte can't be less than 8 bits wide. Which
> one goes in the high-significance position is not specified but it is
> must be either a or d and the other must follow in order.
AFAIK the Standard does not require them to be in the first
byte, just the first addressable unit. For example, they
might be the low-order bits in a four byte unsigned int
on a machine that is "big endian", ie, they would be in
the fourth byte rather than the first.
Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Bit-field union bug Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 12:23 -0800 Re: Bit-field union bug Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-24 21:15 +0000
csiph-web