overflowing bitfields

R

.rhavin grobert

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?
 
J

Jack Klein

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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
J

James Kanze

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top