Mac "<function> was used with no prototype before its definition" error

kainjow

Moderator emeritus
Original poster
Jun 15, 2000
7,958
3


I am getting this error in a file with C functions. The function is implemented like so:
Code:
static OSStatus installCustomMenu() {
 ...
}
and is defined in the header like so:
Code:
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

Moderator emeritus
Jul 24, 2002
24,638
61
Harrogate
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

Moderator emeritus
Original poster
Jun 15, 2000
7,958
3
#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

Moderator emeritus
Jul 24, 2002
24,638
61
Harrogate
#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

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
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

Moderator emeritus
Original poster
Jun 15, 2000
7,958
3
I changed the parameter to (void) from just (), and that made it work. I have no idea why. :confused: