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

♀尐吖头ヾ 提交于 2020-01-02 08:03:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!