What do these warnings mean C

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 was trying to get rid of my code. What does each warning mean and how best to get rid of it?

+4
source share
5 answers

They mean that you are not declaring a return type for your functions and that you are not using return after your compiler has added a default return type for int for these functions. Declare them all void and the warnings disappear.

EDIT: and declare your functions before using them, also in the header file or just above the code in which they are called.

+6
source

You have a function prototype that looks like this:

 choice(); 

In C89, this was good, and it implicitly became:

 int choice(); 

In C99, you need to explicitly add the return type. It also looks like you intend it to be invalid, so you need to:

 void choice(); 
+3
source

It looks like you have a choice of function () that you did not give a return type. If you intend it to be empty, declare as:

 void choice(); 
+2
source

You do not declare your functions before using them. C requires you to declare functions before using them. Usually you place ads 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() { } 
+1
source

You use functions before declaring them. You may simply be absent, including the title.

Error message explanation: Wimplicit-function declaration (C and Objective-C only) Provide a warning whenever the function is used before the declaration. In C99 mode (-std = c99 or -std = gnu99), this warning is enabled by default, and it turns into an error through -pedantic-errors. This warning is also included by -wall.

0
source

Source: https://habr.com/ru/post/1488521/


All Articles