I’m just starting out on C language and I’m getting stuck on a seemingly very basic code. Now, I’m using gcc to compile on ubuntu terminal and I keep getting this warning:
return type defaults to ‘int’ [-Wimplicit-int]
NOTE: the program compiles and runs just fine, but this warning bugs me. Please help.
Here’s my code:
#include <stdio.h>
myFunction(char name[])
{
printf("Hello %sn", name);
}
int main(void)
{
myFunction("Liam")
myFunction("John")
myFunction("Anne")
return (0);
}
2
Answers
myFunction(char name[])
is invalid C. In ancient days this syntax with no return type was allowed, the return type would then default toint
. gcc kept this dangerous "feature" as a non-standard extension. Other compilers might just tell you that the program is invalid and refuse to generate an executable.Change to:
Your function
myFunction
does not declare any return types. If you do not specify any, C will assume you implicitly mean to return an int.If you don’t mean to return anything, you should declare it as
void myFunction
.