开发者

"No previous prototype for function" warning

开发者 https://www.devze.com 2023-03-28 15:00 出处:网络
i use shareKit to myself program . but in the FBConnectGlobal, there are some warning, NSMutableArray* FBCreateNonRetainingArray() {

i use shareKit to myself program .

but in the FBConnectGlobal, there are some warning,

NSMutableArray* FBCreateNonRetainingArray() {
  CFArra开发者_如何学编程yCallBacks 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"


According to c standard, declaring the prototype as

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

solves the issue.


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消