This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Does GCC have a flag that would make it give warnings if an enum value is mixed up with an int? Like this:
void f ( int );
typedef enum { AA, BB, CC } T;
f (AA) -- complain please int x = CC; -- ditto
No, because this is a kind of integer promotion which is allowed by the standard ([conv.prom]/2), so there is nothing wrong about it. Converting the other way (int -> enum) is instead forbidden and should be rejected by GCC.
In C, you can have both implicit conversions. C++ says that you can't go from int to enums implicitly
"In fact, some UNIX C compilers implement a weakly typed form of enumerations in which some conversions between enumerated types and integers are not permitted without casts"
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |