To build on John's answer, most C compilers will allow you to call a function that is not yet known by the compiler. This allows you to separate the implementation of your functions from the call site in the hope that it will allow incremental building, and allow you to use functions from external sources.
In this case the compiler assumes the function returns an int
, and all arguments are of typeint
as the compiler hasn't been provided a function prototype (either outside any function in the file or in a header file). The reasons for the compiler making this assumption are historical and are based on the development of K&R C
If you turn on strict ansi mode (-std=c99 -pedantic
for gcc
) the file will fail to compile because it is generally accepted as a bad idea to call a function without knowing the argument types.
This is why you get the warning.
You should put the following at the top of your source file:
char *myfunction(int p);
note the semicolon at the end of the line tells the compiler this is a function prototype and not the implementation - which the compiler assumes comes from some other translation unit.