PDA

View Full Version : "<function> was used with no prototype before its definition" error




kainjow
Jul 10, 2007, 04:20 PM
http://img164.imageshack.us/img164/566/xcodewarntw4.gif

I am getting this error in a file with C functions. The function is implemented like so:
static OSStatus installCustomMenu() {
...
}
and is defined in the header like so:
static OSStatus installCustomMenu();
It is being called from a function above it, and I'm still seeing this error (warning actually).

Anyone know how to get rid of it? The .m file is #import-ing the .h file normally, so it should see that it's defined in the header.



robbieduncan
Jul 10, 2007, 04:24 PM
Note sure about this but #import is very Obj-C based. Can you #import instead #include straight C based stuff. I don't see why it would make any difference at a .h level as the header files would look the same.

Although now I've read that a bit more carefully: you are defining code in the .h. I'd certainly try #include instead of #import then. I seem to remember code headers does not work when #import ed

kainjow
Jul 10, 2007, 04:28 PM
#include doesn't remove the warning. I think #import doesn't do anything special for non-Objective-C files, but I didn't write the original files :)

robbieduncan
Jul 10, 2007, 04:31 PM
#include doesn't remove the warning. I think #import doesn't do anything special for non-Objective-C files, but I didn't write the original files :)

#import removes the need for protective #defines and the like. It should do that for all headers (obj-c or otherwise).

Clearly something is compiler "noticing" the function definition exists. It should clearly pick up the forward declaration if nothing else so that's very weird. Have you tried creating a simple .h file and defining a function of your own to see if it works?

lazydog
Jul 10, 2007, 04:54 PM
Hi,

I'm not entirely sure about this but perhaps it has something to do with the fact that it is a static function? Since it is static there is no need to prototype it in a seperate .h file as it can't be called from any other file other than the one it is defined in.

b e n

kainjow
Jul 10, 2007, 05:27 PM
I changed the parameter to (void) from just (), and that made it work. I have no idea why. :confused:

gnasher729
Jul 10, 2007, 06:02 PM
Why do you have the prototype for a static function in a header file?

kainjow
Jul 10, 2007, 06:07 PM
Why do you have the prototype for a static function in a header file?

No idea, the code wasn't written by me, I'm just trying to get rid of the warning.