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

Discussion in 'Mac Programming' started by kainjow, Jul 10, 2007.

  1. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #1
    [​IMG]

    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.
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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
     
  3. thread starter Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #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 :)
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    #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?
     
  5. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #5
    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
     
  6. thread starter Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    I changed the parameter to (void) from just (), and that made it work. I have no idea why. :confused:
     
  7. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #7
    Why do you have the prototype for a static function in a header file?
     
  8. thread starter Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    No idea, the code wasn't written by me, I'm just trying to get rid of the warning.
     

Share This Page