DPRG
DPRG List  



[DPRG] I didn't want this to work: C structure confusion

Subject: [DPRG] I didn't want this to work: C structure confusion
From: Ed Okerson ed at okerson.com
Date: Fri Sep 8 21:50:29 CDT 2006

Dale,

>  > The allowed types for bitfields in a struct or union in C are only int,
>  > signed int or unsigned int.  What is happening here is the compiler
>  > preprocessor is using the default promotion of your defined types to
int,
>  > after that assignment from any other type with the same default
promotion
>  > will work without generating any warnings or errors.
>
> Well, fiddlesticks.  Any way to do what I'm trying to do?

I don't know if C++ has the same restriction on the types of bitfields, it
is generally much stricter about only allowing like types to be assigned
to variables.  However it does come with other baggage, that may not be
suitable for a small system with limited resources.  It might be worth
trying to just rename your source file to end with .cpp and recompile,
assuming you have the C++ cross compiler installed for your target system.
 It would be interesting to compare the sizes of the resulting files from
the C and C++ compiles.

Ed


More information about the DPRG mailing list