Re: enum safety



Army1987 wrote:
Ian Collins wrote:

Sard wrote:
Hi,

Page 39 K&R2 says

'Although variables of enum types may be declared, compilers need not
check that what you store in such a variable is a valid value for the
enumeration'

This is why (in my opinion) enums are horribly broken in C.
Not necessarily. For example, you can have an object which can contain
a number up to 10 as numbers, and 11, 12 and 13 with special meanings. E.g.
enum rank { ACE = 1, JACK = 11, QUEEN = 12, KING = 13 };
enum rank foo = 7;

That illustrates the problem perfectly, you declare declare a valid
range of values for rank and then legally assign some other arbitrary
value to it. Useless.

--
Ian Collins.
.



Relevant Pages

  • Re: Enumerated types
    ... Enum ACGroup ... I cannot then access the members of the group. ... One alternative I could try, in the mean time, is to declare a string array ...
    (microsoft.public.access.formscoding)
  • Re: non-static method gotcha
    ... the declared enum, 'SubmissionSite' in your example. ... Its effect is to declare that C is not an inner class. ... extends the immediately enclosing enum type. ... decompiled anonymous class. ...
    (comp.lang.java.help)
  • Re: enum safety
    ... 'Although variables of enum types may be declared, ... you declare declare a valid ...
    (comp.lang.c)
  • Re: Newbie Question
    ... It may be a problem but the compiler error clearly stated that he tried to ... declare a method where only a class, delegate, enum, interface, or struct is ... >> public static extern int SendCharFmtMsg(IntPtr hWnd, int Msg, int ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: stratgies for organizing elements in a passed array
    ... enumeration is nothing except a special syntax to declare a set of named ... You don't need f2003 to declare a set of named constants. ... to have symbolic names for the various keywords. ... I use an old preprocessor to get the equivalent of an enum. ...
    (comp.lang.fortran)