Given the following code
#include <stdio.h>
typedef enum{
ISP_INPUT_NONE,
ISP_INPUT_DOLBY
} UserStream_t;
int someFunc(const char * str) {
printf("%s", str);
return 0;
}
int main(int argc, char** arg)
{
int a = ISP_INPUT_NONE;
someFunc(ISP_INPUT_NONE);
someFunc(a);
return 0;
}
The second call triggers an integer conversion warning, but the first doesn't.
gcc -Wall test.c
test.c: In function ‘main’:
test.c:17:14: warning: passing argument 1 of ‘someFunc’ makes pointer from integer without a cast [-Wint-conversion]
17 | someFunc(a);
| ^
| |
| int
test.c:8:27: note: expected ‘const char *’ but argument is of type ‘int’
8 | int someFunc(const char * str) {
| ~~~~~~~~~~~~~^~~
Are enum silently converted to pointers?
I thought C enums were considered as integers. I would like the first call to generate the same warning as the second.
ISP_INPUT_DOLBY:D .ISP_INPUT_NONEis0, so it's implicitly converted tovoid*.int. Both an enumeration constant with value zero and the integer constant0qualify as a null pointer constant. (This, “null pointer constant,” is the proper term.NULLis the name of a macro.)-Wnon-literal-null-conversion, which is on by default. You should specify the compiler you are using.