I have a very simple Objective-C sample
#import <Foundation/Foundation.h>
int littleFunction();
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool
= [[NSAutoreleasePool alloc] init];
// insert code here...
NSLog(@"Hello, World!");
[pool drain];
return 0;
}
int littleFunction()
{
return 0;
}
With this code I get a “no previous prototype for function” warning for littleFunction but as you can all see there is a declaration before main. What is wrong here? It seem the compiler is unable to match the declaration with the function implementation.
If I change both like this:
int littleFunction(void)
it works perfectly.
I am using the latest Xcode 4
In C,
int littleFunction();is not really a prototype. It doesn’t specify how many (or what sort of) parameters the function accepts.The actual wording in C99 is in §6.7.5.3 item 14:
The footnote refers to this section in the Future language directions:
(Note: this is still present in the C11 draft I have (n1570).)
Back in §6.7.5.3, item 10:
So you have to explicitly specify
int foo(void);if you want to prototype a function that doesn’t take parameters. Objective-C has the same rules.