Joe
Joe

Reputation: 47609

"warning: initialization makes pointer from integer without a cast". But I don't think it does

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?

Upvotes: 3

Views: 4920

Answers (3)

Joe
Joe

Reputation: 47609

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.

Upvotes: 2

nothrow
nothrow

Reputation: 16168

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.

Upvotes: 7

Tarydon
Tarydon

Reputation: 5183

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.

Upvotes: 0

Related Questions