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?
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.
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();
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();
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() {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With