问题
I'm getting a strange compile warning. It's intermittent, and doesn't appear every build. I get the warning "initialization makes pointer from integer without a cast" for the following line:
callbackTable *callbacks = generateLoggingCallback();
and, for completeness, this gives the same outcome
callbackTable *callbacks;
callbacks = generateLoggingCallback();
the function prototype for that is:
callbackTable *generateLoggingCallback();
and the implementation is
callbackTable *generateLoggingCallback() { ... }
So, I'm not quite sure what the problem is. Ideas?
回答1:
If it's pure C, isn't there a warning about 'unknown' function? if yes, then the compiler decides that the unknown function returns int, and continues on.. check if proper headers are included, and the function is declared before it's used.
回答2:
Found the answer, as per this. I wasn't referencing the header file containing the function prototype. So, as I understand it, the compiler was guessing at the function's type signature, and guessing the return type as the default int
.
It all worked because the implementation file containing the function was included in the build and the return type (assumed to be an int
) was just placed in a variable declared as a pointer.
回答3:
Is the function generateLoggingSmfReaderCallback or generateLoggingCallback? If the function name in the prototype does not match the one in your call, the strange thing then is only that you are not getting the warning on each build.
来源:https://stackoverflow.com/questions/1980142/warning-initialization-makes-pointer-from-integer-without-a-cast-but-i-dont