Re: overflowing bitfields
On Oct 18, 4:30 am, Jack Klein <jackkl...@spamcop.net> wrote:
> On Wed, 17 Oct 2007 07:41:08 -0700, ".rhavin grobert" <cl...@yahoo.de>
> wrote in comp.lang.c++:
> > is there any defined behaviour when doing this:
> > __________________________
> > // lets assume you defined 'BYTE'
> > // to whatever is a 8-bit-byte on your sys;-)
> > struct x {
> > BYTE nTreeBit : 3;
> > BYTE nFiveBit : 5;
> > }
> > x.nTreeBit = 42;
> > __________________________
> > my i assume nFiveBit stayes untouched?
> Yes, you may. And the value in nTreeBit is implementation-defined.
Not if BYTE is an unsigned type. If BYTE is unsigned, nTreeBit
is guaranteed to be 2.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
|