Re: enum size in WinCE compiler



As far as I can tell, no, there's no way to change the size of the enum.
Let me ask you this, though: why would you want to do that? Any memory
savings from reducing the size of an enum is going to be swamped by the
slowness of accessing it, at least on any non-x86 processor. If you have a
packed structure that you're sending over the network or something, you're
best-off just declaring the size of the field as an intrinsic type, char,
short, or whatever, and assigning from your enum, as necessary.

-----

typedef enum { packet1 = 1, packet2 = 2, packet3 = 3 } PacketType;

#pragma pack( push, 1 )

typedef struct
{
char packetType;
short packetLength;
unsigned char packetData[1];
} NetStruct;

#pragma pack( pop )

etc.

packet.packetType = (char)packet1;

-----

Paul T.

"Dinesh" <mittals.dinesh@xxxxxxxxx> wrote in message
news:Ot6g%23FGUIHA.5980@xxxxxxxxxxxxxxxxxxxxxxx
Thanks , Could you please give me the MSDN reference to this extension. I
couldn't see it in WinCE documentation and when I tried using this syntax,
I get compilation errors!

cheers

"James Hayhurst" <jameshay@xxxxxxxxxxxxx> wrote in message
news:evZTA%23BUIHA.4360@xxxxxxxxxxxxxxxxxxxxxxx
I believe you can do something like:

enum MyEnum : unsigned char {
// ...
};


I think that this is an MS specific extension though, so it probably
won't be portable.

-James

"Dinesh" <mittals.dinesh@xxxxxxxxx> wrote in message
news:u$D4ro7TIHA.6036@xxxxxxxxxxxxxxxxxxxxxxx
Hi All,
Is there anyway to alter the size of enum data types with WinCE
compiler? I understand in WinCE OS, a enum data types alwayss assumes 4
bytes. Several compilers like GCC, ARM Compilers definitely provide the
option, why not wince?

cheers,
Mithi





.



Relevant Pages

  • Re: enum safety
    ... 'Although variables of enum types may be declared, compilers need not ... In this case, c is of type char*, purple is of type enum ... creates a series of constants (which, oddly enough, are of type int, ...
    (comp.lang.c)
  • Re: resolving a warning error
    ... >This works on several systems and compilers, but fails on aix xlc. ... Not if you invoke them in conforming mode: ... >warning messages and without declaring the enum? ...
    (comp.lang.c)
  • Re: Header files with enums instead of defines?
    ... You also can't #ifdef an enum. ... in those compilers you would have ... to define 'xerror' as 'enum ERRVALS xerror', ...
    (freebsd-arch)
  • Re: Why no/limited checking on enum values ?
    ... but compilers are always allowed to ... >An enum type is a symbolic name for an int. ... C89 standard appears to me to allow even "enum C" to use an unsigned ... standards do allow it, would not survive in the marketplace....) ...
    (comp.lang.c)
  • Re: No enumeration data type in Fortran?
    ... compiler that makes one [enum] other than int won't work with a F2003 ... compilers that don't make all enums int). ... compilers, and they knew more about the subject than I did or do. ... Well, the cases I was thinking of involve pass by reference, especially between Fortran and C. ...
    (comp.lang.fortran)