Re: enum safety
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Sun, 10 Feb 2008 08:32:45 +1300
Army1987 wrote:
Ian Collins wrote:
Sard wrote:Not necessarily. For example, you can have an object which can contain
Hi,This is why (in my opinion) enums are horribly broken in C.
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'
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.
.
- Follow-Ups:
- Re: enum safety
- From: Keith Thompson
- Re: enum safety
- From: Anonymous
- Re: enum safety
- References:
- enum safety
- From: Sard
- Re: enum safety
- From: Ian Collins
- Re: enum safety
- From: Army1987
- enum safety
- Prev by Date: Re: The comma operator, and assigning twice between sequence points
- Next by Date: Re: Reverse a linked list using Recursion
- Previous by thread: Re: enum safety
- Next by thread: Re: enum safety
- Index(es):
Relevant Pages
|