“No previous prototype for function” warning

前端 未结 4 1628
情歌与酒
情歌与酒 2021-02-01 12:59

i use shareKit to myself program .

but in the FBConnectGlobal, there are some warning,

NSMutableArray* FBCreateNonRetainingArray() {
  CFArrayCallBacks c         


        
相关标签:
4条回答
  • 2021-02-01 13:40

    Is it a global function? Add "static" if it is only used in the current file.

    The possible reason is as below:

    no previous prototype for `foo'

    This means that GCC found a global function definition without seeing a prototype for the function. If a function is used in more than one file, there should be a prototype for it in a header file somewhere. This keeps functions and their uses from getting out of sync

    If the function is only used in this file, make it static to guarantee that it'll never be used outside this file and document that it's a local function

    0 讨论(0)
  • 2021-02-01 13:43

    To clarify Eric Dchao's answer above, someone at facebook apparently didn't put a "static" in front of that BOOL?

    Anyways, changing from this

    BOOL FBIsDeviceIPad() {
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return YES;
      }
    #endif
      return NO;
    }
    

    to this

    static BOOL FBIsDeviceIPad() {
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return YES;
      }
    #endif
      return NO;
    }
    

    fixed it for me.

    0 讨论(0)
  • 2021-02-01 13:44

    According to c standard, declaring the prototype as

    NSMutableArray* FBCreateNonRetainingArray(void);
    //      --------------->                  ^^^^   
    // Yes, with the void as the parameter
    

    solves the issue.

    0 讨论(0)
  • 2021-02-01 13:53

    UPDATE: Disable warnings is not a good solution, check @Derek Bredensteiner's answer.

    In Xcode 4, go to your project's Build Settings. Search for "prototype". There should be an option called "Missing Function Prototypes"; disable it.

    via here

    0 讨论(0)
提交回复
热议问题