macro for enum operations

Ravikiran Rajagopal ravi at ee.eng.ohio-state.edu
Wed Sep 10 21:20:32 BST 2003


On Wednesday 10 September 2003 08:04 am, Guillaume Laurent wrote:
> On Wednesday 10 September 2003 13:15, Lubos Lunak wrote:
> >  Looks like a good idea, even though creating enum values that are not
> > defined in the enum feels a bit scary, as enum is usually seen as 'one
> > value from a set',
>
> Actually an enum can have any value which can be represented by the number
> of bits of its largest defined value. So the boolean operators are
> perfectly legal.

In C++, enums have sizes that are not necessarily the same as those of ints of 
any form. If I understand the standard right (correct me if I am wrong), the 
size can actually be larger than that of longs. So Simon's patch is not 
guaranteed to be safe in all corner cases. I know this sounds like one of the 
language lawyers on comp.lang.c++.moderated :-)

Please see Dirk's recent commits regarding implicit conversion of enums to 
ints and the problems with gcc 3.4. I am particularly concerned about the "~" 
operator because the return value needs to be converted to EnumType again and 
I wonder whether truncation would cause problems with 1s complement vs 2s 
complement.

Apologies if this OT for this list.

Regards,
Ravi




More information about the kde-core-devel mailing list