Possible Duplicate:
Error: No previous prototype for function. Why am I getting this error?
I have a function that I prototyped in the header file, however Xcode still gives me warning No previous prototype for the function 'printBind'. I have the function setBind prototyped in the same way but I do not get an warning for this function in my implementation.
CelGL.h
#ifndef Under_Siege_CelGL_h
#define Under_Siege_CelGL_h
void setBind(int input);
void printBind();
#endif
CelGL.c
#include <stdio.h>
#include "CelGL.h"
int bind;
void setBind(int bindin) { // No warning here?
bind = bindin;
}
void printBind() { // Warning here
printf("%i", bind);
}
In C, this:
is not a prototype. It declares a function that returns nothing (
void) but takes an indeterminate list of arguments. (However, that list of arguments is not variable; all functions taking a variable length argument list must have a full prototype in scope to avoid undefined behaviour.)That’s a prototype for the function that takes no arguments.
The rules in C++ are different – the first declares a function with no arguments and is equivalent to the second.
The reason for the difference is historical (read ‘dates back to the mid-1980s’). When prototypes were introduced into C (some years after they were added to C++), there was an enormous legacy of code that declared functions with no argument list (because that wasn’t an option before prototypes were added), so backwards compatibility considerations meant that
SomeType *SomeFunction();had to continue meaning ‘a function that returns aSomeType *but for which we know nothing about the argument list’. C++ eventually added theSomeType *SomeFunction(void);notation for compatibility with C, but didn’t need it since type-safe linkage was added early and all functions needed a prototype in scope before they were defined or used.Note that C23 finally brings C into alignment with C++ and the empty parenthesis notation means that the function declaration is a prototype for a function taking no arguments.