Re: enum question.
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Sun, 11 Mar 2007 20:00:56 +1300
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.
--
Ian Collins.
.
- Follow-Ups:
- Re: enum question.
- From: CBFalconer
- Re: enum question.
- From: santosh
- Re: enum question.
- References:
- enum question.
- From: At_sea_with_C
- Re: enum question.
- From: CBFalconer
- Re: enum question.
- From: Ian Collins
- Re: enum question.
- From: CBFalconer
- enum question.
- Prev by Date: Re: Rvalue of struct type
- Next by Date: Re: Rvalue of struct type
- Previous by thread: Re: enum question.
- Next by thread: Re: enum question.
- Index(es):
Relevant Pages
|