Let's assume I have
struct foo
{
unsigned int bar : 7;
unsigned int next_field : 1;
}
void funct()
{
struct foo demo;
demo.next_field = 0;
unsigned char *barptr = (unsigned char *)&demo;
/*1 = 00000001, bar can contain only 7 bits*/
*barptr = 1;
}
since bar is 7 bit where as char is 8 bits, what will happen? Will bar be filled with zeros and next_field contain the 1?
Will the result be:
0000000 1
|_____| |_|
bar
or
0000001 0
|_____| |_|
bar
or:
0000000 0
|_____| |_|
bar
I would check using my compiler but I don't know wether this behavior is implementation-defined, in witch case the compiler can be misleading.