Possible Duplicate:
What is a “translation unit” in C++
It is often said that the static variables declared in C/C++ are not visible across compilation units ? Does this mean that each .c or .cpp file is a separate compilation unit ? What about a .h file and the static variables declared in the .h file ? Is .h file also considered as a separate compilation unit ?
Header files have no separate life, only their content is #included
into .c or .cpp files. But since #include
is handled by the preprocessor, the compiler has no knowledge about distinct header files; it only sees the resulting code listing as input. This is what is called a compilation unit: a source file with all its #include
directives replaced by the content of the relevant header files and all other preprocessor statements processed (like #define
, #ifdef
etc.).