skip to Main Content

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


  1. myFunction(char name[]) is invalid C. In ancient days this syntax with no return type was allowed, the return type would then default to int. 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:

    void myFunction(char name[])
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search