enum's & KConfigBase

Stefan Teleman steleman at nyc.rr.com
Tue Jan 17 00:14:54 GMT 2006


On Monday 16 January 2006 18:58, Thomas Braxton wrote:
> True, but how many enums that are used in KDE would this really matter for?
> If you had an enum that needed special handling you would just have to
> write your own implementation of readEntry/writeEntry for that enum. most
> enums in KDE that I've seen so far are more than compensated for with an
> int, besides we aren't talking about the binary representation of an enum,
> it's about the way it is saved as text in a config file.

In an ideal world, it shouldn't matter much (definition of the Ideal World in 
this case: No Negative Enums :-).

It does become a big huge mess when there's some enum initialized with a 
negative "magic" value, and a strict compiler decides to either:
  - raise an Error because, according to the Standard, it does not like 
negative Enums (this is still ok, at least we know there is a problem)
  - not say anything, and happily continue compiling, assigning some bogus 
value to this magic negative enum (which happened to be implemented as an 
union containing an unsigned int, and several bitfields representing the 
actual enum values themselves). unbeknownst to anyone, this negative enum has 
now become a big mess: because of the sign bit, one of the bitfields has 
overflowed, and took out half of the other ones on the way. in some other 
file, in some other library, someone is checking for the value of this enum 
converted to a signed int. none of the enum values match anymore, and the 
library starts behaving like a monkey on crack. :-)

Have fun debugging this. :-)

--Stefan

-- 
Stefan Teleman          'Nobody Expects the Spanish Inquisition'
steleman at nyc.rr.com                          -Monty Python




More information about the kde-core-devel mailing list