« Return to Thread: Does GCC assign any type to enums that can be specified in an assignment operator?

Re: Does GCC assign any type to enums that can be specified in an assignment operator?

by John (Eljay) Love-Jensen :: Rate this Message:

Reply to Author | View in Thread

Hi Michael,

The type for the enum, as given, will be signed int.

Now if you want the enum to be ambiguous, you can do something like this:

enum { Uno = -1, Dos, Tres = 0x80000000 };

That will cause an ambiguous overload of the signed & unsigned assignment
operators, since the 0x80000000 will be taken to be an unsigned int as per
the standard C/C++ interpretation rules.  (Assuming a 32-bit int platform.)

Is that the situation you are running into?

You can "fix" it by doing:

enum { Uno = -1, Dos, Tres = int(0x80000000) };

--Eljay

 « Return to Thread: Does GCC assign any type to enums that can be specified in an assignment operator?