enum safety
- From: Sard <Sardaukary@xxxxxxxxx>
- Date: Fri, 8 Feb 2008 11:22:44 -0800 (PST)
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'
gcc produces an error for the code below as I'm trying to assign a
pointer to char to the a variable of type colour. Is gcc going beyond
the call of duty? Why would the standard allow compilers to accept
such code?
#include <stdio.h>
#include <limits.h>
char* c=0;
enum colours {
Red,Blue
};
int main ()
{
enum colours purple =c ;
return 0;
}
.
- Follow-Ups:
- Re: enum safety
- From: Keith Thompson
- Re: enum safety
- From: Ian Collins
- Re: enum safety
- From: fred . l . kleinschmidt
- Re: enum safety
- Prev by Date: Re: CBF: The Larry Craig of the CLC clique.
- Next by Date: Re: A solution for the allocation failures problem
- Previous by thread: The comma operator, and assigning twice between sequence points
- Next by thread: Re: enum safety
- Index(es):
Relevant Pages
|