LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Header file inclusion (https://www.linuxquestions.org/questions/linux-software-2/header-file-inclusion-944986/)

jayadhanesh 05-14-2012 11:02 PM

Header file inclusion
 
I have huge C code base. There is a header file which is included in multiple C files. How do I know where is the header file included for the first time?

pan64 05-15-2012 01:00 AM

it has no meaning, it depends on the target you want to create. But you can remove/rename that include file and the first error message complaining about it is the answer.

sundialsvcs 05-15-2012 08:38 AM

Some languages "know" whether or not a particular header file is included; others do not.

In many "C" header files you will therefore see this: (e.g. in the imaginary file, xyzzy.h):
Code:

#ifndef HEADER_XYZZY_INCLUDED
  #define HEADER_XYZZY_INCLUDED
  ... included stuff goes here ...
#endif

Notice that, if the symbol is not yet defined, the block will be included, and within that block the symbol (which is arbitrarily but consistently named, and which serves no other purpose...) is defined. Thereafter, no matter how many subsequent times we may see #include "xyzzy.h", and even though the file will be included each time, its contents will be effectively ignored in every case but the first.

It is a cumbersome mechanism, and this why other languages provide a require or use construct (your keyword may vary...) with a more powerful semantics.


All times are GMT -5. The time now is 01:44 PM.