![]() |
What is the following warning in a function where msg is a function name without prototype? |
[Edit] |
[Edit]
In C, each function needs a prototype declaration in the header file so that it can be called from outside of its immediate domain. To speed up compiling, the compiler only looks in the header files for function declarations. This greatly speeds up compiling when the function being called is located in another file. This way, it doesn't have to scan the whole file to make sure you didn't make a mistake. All you need to do to clear this error is to include a function prototype in the header. I'm not sure about C, but you *might* be able to get away with declaring the function at the beginning of the .c file.
Example:
--(file helloworld.h)--
long msg(int, int, char *); //this is the prototype
--(file helloworld.c)--
#include "helloworld.h"
void main()
{
msg(1,5,"Hello World");
}
long msg(int x, int y, char *message)
{
//code to display message here
}
Notice that the prototype only needs the data types, and not the variable names. If you don't want to bother with a header file, you can try putting your declarations at the beginning of your .c file (after the preprocessor directives), I know I've done it that way before but I'm not sure in which cases it will work.
Example:
--(file helloworld.h)--
long msg(int, int, char *); //this is the prototype
--(file helloworld.c)--
#include "helloworld.h"
void main()
{
msg(1,5,"Hello World");
}
long msg(int x, int y, char *message)
{
//code to display message here
}
Notice that the prototype only needs the data types, and not the variable names. If you don't want to bother with a header file, you can try putting your declarations at the beginning of your .c file (after the preprocessor directives), I know I've done it that way before but I'm not sure in which cases it will work.
First answer by NegativeZero. Last edit by NegativeZero. Contributor trust: 2 [recommend contributor]. Question popularity: 1 [recommend question]





