Re: enum safety
- From: Army1987 <army1987@xxxxxxxxx>
- Date: Sat, 9 Feb 2008 12:07:12 +0000 (UTC)
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;
(For example mbrtowc can return a number of bytes, or 0, (size_t)(-2) and
(size_t)(-1) with special meanings. Here an enum won't do it because
constants must fit in an int, but one might have an int-returning function
with similar semantics. Maybe using negative numbers:
enum err_code { OUT_OF_MEMORY = -2, IO_ERROR = -1, MAX = INT_MAX };
--
Army1987 (Replace "NOSPAM" with "email")
.
- Follow-Ups:
- Re: enum safety
- From: Ian Collins
- Re: enum safety
- References:
- enum safety
- From: Sard
- Re: enum safety
- From: Ian Collins
- enum safety
- Prev by Date: Indian Hill, Re: Neatest way to get the end pointer?
- Next by Date: Re: A solution for the allocation failures problem
- Previous by thread: Re: enum safety
- Next by thread: Re: enum safety
- Index(es):
Relevant Pages
|