How 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 function(REG8 reg8) { } int main(void) { function(REG16_A); // Should warn about wrong enum } 回答1: 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