Answer by Brandin for How to make gcc warn about passing wrong enum to a...
For a way to do this in C using GCC's -Wenum-compare (which is enabled by default if you enable -Wall), you must perform a comparison on the enumeration constant before you pass it to the function in...
View ArticleAnswer by Gosha U. for How to make gcc warn about passing wrong enum to a...
With GCC 4.6 you should use -Wconversion and -Werror options to prevent any implicit type conversions. It gives an error with code posted by Paul R. But original code compiles fine anyway. I don't know...
View ArticleAnswer by J. C. Salomon for How to make gcc warn about passing wrong enum to...
As others have pointed out, C does not differentiate between an enumerated type and the underlying integer type. (Some compilers might include type-checking for enums or typedefs as extensions;...
View ArticleAnswer by ulidtko for How to make gcc warn about passing wrong enum to a...
The reason of such behaviour is that you are using C compiler rather than C++. And in C enum types are not really types, enums in C just hold int constants and they can be freely mixed with whatever...
View ArticleAnswer by ulidtko for How to make gcc warn about passing wrong enum to a...
$ g++ test3.cpp -o test3test3.cpp: In function ‘int main()’:test3.cpp:22: error: cannot convert ‘REG16’ to ‘REG8’ for argument ‘1’ to ‘void function(REG8)’
View ArticleAnswer by Paul R for How to make gcc warn about passing wrong enum to a function
The only way I can see of generating a warning is if you are prepared to pass pointers rather than bare enums, e.g.typedef enum{ REG8_A, REG8_B, REG8_C} REG8;typedef enum{ REG16_A, REG16_B, REG16_C}...
View ArticleHow to make gcc warn about passing wrong enum to a function
gcc doesn't seem to produce a warning with the following code. How can I get it to produce a warning?typedef enum{ REG8_A, REG8_B, REG8_C}REG8;typedef enum{ REG16_A, REG16_B, REG16_C}REG16;void...
View Article
More Pages to Explore .....