P
Pritam
Facing a little issue with gcc ( maybe all c compiler have behaves
this way for the problem)
Got a function that takes in a enumerated type. Even if another
enumerated type is passed 'gcc' does not raise any warnings or error.
'g++' generates a error msg for the same. Is there a way to turn on
enum type checks while passing to functions in 'gcc'.
code snippet:
typedef enum {
gcc_enum_type1_val1,
gcc_enum_type1_val2,
gcc_enum_type1_val3,
} gcc_enum_type1_t;
typedef enum {
gcc_enum_type2_val1,
gcc_enum_type2_val2,
gcc_enum_type2_val3,
} gcc_enum_type2_t;
unsigned int foo(gcc_enum_type2_t val)
{
return (unsigned int) val;
}
int main()
{
unsigned int i;
i = foo(gcc_enum_type1_val1);
return 0;
}
gcc compiles the program without any issues.
'g++' complains:
xx.cpp: In function `int main()':
xx.cpp:nn: error: cannot convert `gcc_enum_type1_t' to
`gcc_enum_type2_t' for
argument `1' to `unsigned int foo(gcc_enum_type2_t)'
I want a similar type check in 'gcc' or it is not possible ic 'C'.
Thanks
Pritam
this way for the problem)
Got a function that takes in a enumerated type. Even if another
enumerated type is passed 'gcc' does not raise any warnings or error.
'g++' generates a error msg for the same. Is there a way to turn on
enum type checks while passing to functions in 'gcc'.
code snippet:
typedef enum {
gcc_enum_type1_val1,
gcc_enum_type1_val2,
gcc_enum_type1_val3,
} gcc_enum_type1_t;
typedef enum {
gcc_enum_type2_val1,
gcc_enum_type2_val2,
gcc_enum_type2_val3,
} gcc_enum_type2_t;
unsigned int foo(gcc_enum_type2_t val)
{
return (unsigned int) val;
}
int main()
{
unsigned int i;
i = foo(gcc_enum_type1_val1);
return 0;
}
gcc compiles the program without any issues.
'g++' complains:
xx.cpp: In function `int main()':
xx.cpp:nn: error: cannot convert `gcc_enum_type1_t' to
`gcc_enum_type2_t' for
argument `1' to `unsigned int foo(gcc_enum_type2_t)'
I want a similar type check in 'gcc' or it is not possible ic 'C'.
Thanks
Pritam