Re: enum types and casting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Steve Graegert wrote:

To convert an integral type to an enumeration, use the following semantic:

enum TEST { zero = 0, one, two };
int i1 = 2;
test t1 = static_cast<TEST> (i1); // t1 == two

Steve,

I tried this as follows:

enum BODY { SUN, MOON, STAR } ;
enum PLANET { EARTH, VENUS, MARS, PLUTO } ;
int main ( void )
{
 BODY body ;
 body = static_cast < BODY > ( 3 ) ; // does not give error.
 body = static_cast < BODY > ( PLUTO ) ; // does not give error.
}

but it still does not throw an error even though the enum being casted *to* does not contain an identifier equivalent to the value actually being casted, whether a primitive integer or an identifier belonging to another enum.

Don't you think this is a GCC bug?

Shriramana.

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux