5
 final code2.c:9:1: warning: implicit declaration of function 'choice' is invalid in C99 [-Wimplicit-function-declaration]
choice();
^
final code2.c:12:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
choice()
^~~~~~
final code2.c:23:1: warning: implicit declaration of function 'wrong' is invalid in C99 [-     Wimplicit-function-declaration]
wrong();
^
final code2.c:25:1: warning: implicit declaration of function 'formula1' is invalid in C99 [-Wimplicit-function-declaration]
formula1();
^
final code2.c:27:1: warning: implicit declaration of function 'formula2' is invalid in C99 [-Wimplicit-function-declaration]
formula2();
^
final code2.c:29:1: warning: implicit declaration of function 'formula3' is invalid in C99 [-Wimplicit-function-declaration]
formula3();
^
final code2.c:30:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
final code2.c:32:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
wrong()
^~~~~
final code2.c:35:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
final code2.c:37:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
formula1()
^~~~~~~~
final code2.c:47:1: warning: implicit declaration of function 'question' is invalid in C99 [-Wimplicit-function-declaration]
question();
^
final code2.c:50:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
final code2.c:52:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
formula2()
^~~~~~~~
 final code2.c:63:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
final code2.c:65:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
formula3()
^~~~~~~~
final code2.c:85:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
final code2.c:87:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
question()
^~~~~~~~
final code2.c:99:1: warning: control reaches end of non-void function [-Wreturn-type]
 } 

I have these warnings that I have been trying to get rid of in my code. What do each of the warnings mean and whats the best way to get rid of them?

John Smith
  • 1,089
  • 3
  • 18
  • 37
  • 1
    can you post the code that is causing the warnings? – Mgetz Jun 27 '13 at 15:29
  • 1
    Could you please provide code? The errors are very general. – Lorenz Jun 27 '13 at 15:29
  • I think those warnings come from the source of this question: http://stackoverflow.com/q/17346374/694576 – alk Jun 27 '13 at 15:30
  • 1
    They mean you're not declaring a return type for your functions, and that you're not using `return` statements after your compiler added a default `int` return type for those functions. Declare them all `void` and the warnings will disappear. – Crowman Jun 27 '13 at 15:30
  • http://www.google.com/search?q=gcc+implicit+declaration – Karoly Horvath Jun 27 '13 at 15:32

5 Answers5

6

They mean you're not declaring a return type for your functions, and that you're not using return statements after your compiler added a default int return type for those functions. Declare them all void and the warnings will disappear.

EDIT: And declare your functions before you use them, also, either in a header file, or just above the code where they're called.

Crowman
  • 25,242
  • 5
  • 48
  • 56
3

Looks like you have a function choice() that you did not give a return type. If you intend for it to be void declare as:

void choice();
eliteslayer
  • 190
  • 6
3

You have a function prototype that looks like this:

choice();

In C89, that was fine, and it would implicitly become:

int choice();

In C99, you need to explicitly add the return type. It also looks like you're intending it to be void, so you'll want:

void choice();
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
1

You're not declaring your functions before you use them. C requires that you declare functions before you use them. Typically you put the declarations in a header file.

bad-example.c:

void myFunc() {
   // This causes an implicit declaration; myTest() has not yet been defined.
   myTest(); 
}

void myTest() {
}

good-example.c:

void myFunc();
void myTest();

void myFunc() {
   myTest(); 
}

void myTest() {
}
antiduh
  • 11,853
  • 4
  • 43
  • 66
0

You are using functions before you declared them. You could simply be missing including some header.

Explanation of error message: Wimplicit-function-declaration (C and Objective-C only) Give a warning whenever a function is used before being declared. In C99 mode (-std=c99 or -std=gnu99), this warning is enabled by default and it is made into an error by -pedantic-errors. This warning is also enabled by -Wall.

dbrank0
  • 9,026
  • 2
  • 37
  • 55