On Wed, Sep 18, 2002 at 09:30:24AM -0500, Ben Combee wrote:
> At 01:42 PM 9/18/2002 +0200, you wrote:
>> if you have a CodeWarrior project in which you enable the setting to
>> force enums to be ints, then for example, the boldFont enum becomes a 16 
>> bit wide int [...]
>
> Yes, the Palm OS API headers rely on the "enum is always int" setting to be 
> off.  [...]  For this reason, when I declare my own enums 
> on Palm OS, I like to just typedef the appropriate ranged type to the "enum 
> type", and leave all my enums as a anonymous type, e.g.
> 
> enum { red, blue. green };  typedef UInt8 Color;
> 
> That makes sure my type has exactly the size I want it to have.

Unfortunately it also makes debugging harder (you don't see the symbolic
values of your variables) and subverts the compiler's ability to provide
type checking and other diagnostics:  there's a significant loss of type
checking in C++, and even in C this technique prevents such things as
having the compiler check that you've covered all cases in a switch like
"switch (myColor)" (this is GCC's -Wswitch option).

IMHO the disadvantages outweigh the advantage Ben listed.

There is a way to have these advantages *and* get the size the platform
expects FontType et al to have:  instruct your compiler to follow the
platform's ABI.  One could say that people who willfully choose not to
use the ABI, by turning on things like "enum is always int" (= GCC's
-fno-short-enums) or "four byte integers" (-mno-short), need to be
careful lest they get what they deserve :-).

    John

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to