Wang Yanchao
Wang Yanchao

Reputation: 633

"No previous prototype for function" warning

i use shareKit to myself program .

but in the FBConnectGlobal, there are some warning,

NSMutableArray* FBCreateNonRetainingArray() {
  CFArrayCallBacks callbacks = kCFTypeArrayCallBacks;
  callbacks.retain = RetainNoOp;
  callbacks.release = ReleaseNoOp;
  return (NSMutableArray*)CFArrayCreateMutable(nil, 0, &callbacks);
}

like this method, it warning:"No previous prototype for function FBCreateNonRetainingArray"

Upvotes: 45

Views: 31905

Answers (4)

fannheyward
fannheyward

Reputation: 19277

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

Upvotes: 28

daveswen
daveswen

Reputation: 723

According to c standard, declaring the prototype as

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

solves the issue.

Upvotes: 62

basicthinker
basicthinker

Reputation: 318

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

Upvotes: 7

Derek Bredensteiner
Derek Bredensteiner

Reputation: 2916

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.

Upvotes: 50

Related Questions