Re: Question about "enums"




Ian Collins wrote:
Bill Pursell wrote:
Ian Collins wrote:


Assigning any other value to <an enum type> is undefined. Unfortunately C
compilers don't regard this as an error, which renders enums little more
than symbolic constants.


gcc gives a warning when you do a switch on an enum type, indicating
that you have failed to explicitely specify behavior for any of the
listed cases. I find that very useful.

But not with the following, which I've always considered a huge hole in
the C standard.

enum loop { NO, YES};
enum loop okloop=YES;

void f( enum loop v )
{
}

int main(void)
{
f( 42 );

okloop = 42;

return 0;
}

Agreed. I've never written a compiler, but it strikes me that that
should be a fairly simple warning to emit. Does anyone know why such
warnings are not given?

.



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: enum size in WinCE compiler
    ... As far as I can tell, no, there's no way to change the size of the enum. ... unsigned char packetData; ... Is there anyway to alter the size of enum data types with WinCE ... Several compilers like GCC, ...
    (microsoft.public.windowsce.embedded)