简体   繁体   中英

warning: implicit declaration of function - order of includes matter?

I have the following sample code snippet of code from a main.c which calls 3 functions, with 3 headers - which is giving me warnings for a reason unknown:

 #include "header1.h" #include "header2.h" #include "header3.h" int main() { function1(); // this is from header1 function2(); // this is from header2 function3(); // this is from header 3 } 

Basically, after using gcc, the functions 2 & 3 will produce the warning. However, after rearranging the code to something like this:

 #include "header3.h" #include "header1.h" #include "header2.h" int main() { function1(); // this is from header1 function2(); // this is from header2 function3(); // this is from header 3 } 

It will then give me the warning that functions 1 & 2 are implicit. What am I doing wrong here?

your include file 1 should look like this:

#ifndef __REZON_FUNCTIONS1__ 
#define __REZON_FUNCTIONS1__ 

#endif

The other two files should be similar with the macro name changed accordingly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM