Msgstr "warning: initialization makes a pointer from a whole without a cast". But I do not think it

I get a weird compilation warning. It is intermittent, and every assembly does not appear. I get a warning "initialization makes a pointer from a whole without casting" for the following line:

callbackTable *callbacks = generateLoggingCallback(); 

and, for completeness, this gives the same result

 callbackTable *callbacks; callbacks = generateLoggingCallback(); 

function prototype for this:

 callbackTable *generateLoggingCallback(); 

and implementation -

 callbackTable *generateLoggingCallback() { ... } 

So I'm not quite sure what the problem is. Ideas?

+3
source share
3 answers

If it is pure C, is there no warning about an "unknown" function? if so, then the compiler decides that the unknown function returns int and continues .. check to see if the appropriate headers are included and the function is declared before using it.

+7
source

Found the answer according to this . I did not refer to the header file containing the function prototype. So, as far as I understand, the compiler guessed the signature of the type of the function and guessed the type of the return value as the default value int .

All this worked because the implementation file containing this function was included in the assembly, and the return type (assumed as int ) was simply placed in a variable declared as a pointer.

+2
source

Is the generateLoggingSmfReaderCallback or generateLoggingCallback function? If the function name in the prototype does not match the name in your call, the strange thing is then only that you do not receive a warning in each assembly.

0
source

Source: https://habr.com/ru/post/1500421/


All Articles