enum's & KConfigBase
brax108 at cox.net
Tue Jan 17 00:45:55 GMT 2006
On Monday 16 January 2006 18:14, Stefan Teleman wrote:
> 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. :-)
I don't see how we don't have the same problem debugging this now, because
most enums _are_ stored with "writeEntry(key, static_cast<int>(enumValue))"
when written to a config file. If you look at the macro definition it is the
same exact code, the macro just makes it so that you can write
"writeEntry(key, enumValue)". Like I said if you have a weird enum, then you
will have to write your own readEntry/writeEntry.
More information about the kde-core-devel