G
gert.vierman
Hello,
Here is some code mixing bitfields and longs in an union.
Any comments on the validity and portability of this program ?
Thank you very much.
#include <stdio.h>
union msg_t {
struct elem {
unsigned long foo: 16;
unsigned long bar: 12;
unsigned long type: 4;
unsigned long length: 32;
} elem;
unsigned long data[2];
} ;
int main(int argc, char **argv)
{
union msg_t msgh;
msgh.elem.bar = 0x2;
msgh.elem.foo = 0x3;
msgh.elem.length = 0x100;
printf("%08x\n", msgh.data[0]);
printf("%08x\n", msgh.data[1]);
return 0;
}
Here is some code mixing bitfields and longs in an union.
Any comments on the validity and portability of this program ?
Thank you very much.
#include <stdio.h>
union msg_t {
struct elem {
unsigned long foo: 16;
unsigned long bar: 12;
unsigned long type: 4;
unsigned long length: 32;
} elem;
unsigned long data[2];
} ;
int main(int argc, char **argv)
{
union msg_t msgh;
msgh.elem.bar = 0x2;
msgh.elem.foo = 0x3;
msgh.elem.length = 0x100;
printf("%08x\n", msgh.data[0]);
printf("%08x\n", msgh.data[1]);
return 0;
}