|
Prev: To take screen shot
Next: generique medicaments canada propecia suisse achat propecia canada discret generique pharmacie us usa propecia suisse propecia belgique Generique Inde
From: Christoph Bartoschek on 19 Apr 2008 09:53 Hi, does POSIX guarantee anything about bitfield layout: union Test { unsigned char a; struct Data { unsigned first:4; unsigned second:3; unsigned third:1; } data; }; If I assign 0xF1 to a. Can one assume that first has the value 0xF, second the value 0x0 and third the value 0x1. Thanks Christoph Bartoschek
From: Måns Rullgård on 19 Apr 2008 10:22 Christoph Bartoschek <bartoschek(a)gmx.de> writes: > Hi, > > does POSIX guarantee anything about bitfield layout: Very little. > union Test { > unsigned char a; > struct Data { > unsigned first:4; > unsigned second:3; > unsigned third:1; > } data; > }; > > If I assign 0xF1 to a. Can one assume that first has the value 0xF, second > the value 0x0 and third the value 0x1. No. To be on the safe side, don't assume anything at all. -- M�ns Rullg�rd mans(a)mansr.com
From: David Schwartz on 19 Apr 2008 13:18
On Apr 19, 6:53 am, Christoph Bartoschek <bartosc...(a)gmx.de> wrote: > Hi, > > does POSIX guarantee anything about bitfield layout: > > union Test { > unsigned char a; > struct Data { > unsigned first:4; > unsigned second:3; > unsigned third:1; > } data; > > }; > > If I assign 0xF1 to a. Can one assume that first has the value 0xF, second > the value 0x0 and third the value 0x1. No. The effect of reading from an entry in a union other than the one you last wrote to is undefined. DS |