Re: enum question.
- From: "santosh" <santosh.k83@xxxxxxxxx>
- Date: 10 Mar 2007 23:20:05 -0800
Ian Collins wrote:
CBFalconer wrote:
Ian Collins wrote:Sorry, but it is. You can't assign an int to an enum variable without a
CBFalconer wrote:
At_sea_with_C wrote:
.... snip ...
Why is the assignmnt with SOMEVAL allowed? I thought an enum type
was only allowed to have values specified in the enumeration list.
Why is compiler not even warning about it? Am I wrong?
Stronger typed languages will catch it, but not C. In C an enum
just defines an integer type, with some specific named values.
This is basically the price you pay for allowing any disconnected
enum values, e.g something like 0,1,2, 10, 100.
I don't think the range has anything to do with it. C++ enums can
have disconnected values and still enforce valid assignments.
C++ doesn't care how much code it generates. Think about the run
time code needed to do the checking (it can't be done at compile
time, because the values are ints and can be the results of
expressions or function calls).
cast in C++. There isn't any runtime checking, so you can assign
bollocks values if you go out of your way to do so.
That's true. C++ does require a cast to assign out-of-range values,
(or the wrong types?), to enums.
enum seems to be a full-fledged type in C++, whereas, in C, it appears
to simply be a method to define a list of int constants.
.
- References:
- enum question.
- From: At_sea_with_C
- Re: enum question.
- From: CBFalconer
- Re: enum question.
- From: Ian Collins
- Re: enum question.
- From: CBFalconer
- Re: enum question.
- From: Ian Collins
- enum question.
- Prev by Date: Re: ANSI C syntax ?
- Next by Date: Re: ANSI C syntax ?
- Previous by thread: Re: enum question.
- Next by thread: Re: enum question.
- Index(es):
Relevant Pages
|
|