This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Rant and proposal about bitfield semantics in our IL and the C/C++ Frontend


Hi,

On Tue, 15 Jan 2008, Joseph S. Myers wrote:

> On Mon, 14 Jan 2008, Richard Guenther wrote:
> 
> > Can you clarify on the resulting promotions?  As I remember the
> > standard defines promotions based on the representable values, so
> > long : 15 gets promoted to int, but long : 33 doesn't get promoted.
> > In the C++ FE at least we promote to the _declared_ type, that is,
> > to long in this case.  (Which I find more natural, but may be not
> > what the standard says).
> 
> Types (including the bit-field width as part of the type) narrower than 
> int are promoted based on representable values (so to int).  Types wider 
> than int are left unchanged by the promotions.

Right.  And IMHO that's a deficiency.  From a language esthetics 
perspective also those larger bit-fields should be promoted, namely to the 
next larger integer type (which surely exists for compilers implementing 
bit-fields larger than int).

Doing arithmetic on small bit-fields on the (larger) promoted type, but 
doing them on large bit-fields on the exact width creates an asymmetry.  
That asymmetry then reflects into the code generator as ugly special 
cases, and actually also in horrible intermediate code (like doing bit 
mask operations after all arithmetic).

So, if there's opportunity to fix the C standard in the next round by 
including language for promotions wider than int, that would be IMO much 
better than introducing first-class bit-field types.  It would also mirror 
current behaviour of many compilers.


Ciao,
Michael.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]