Re: [Dev-C++] Where to include files
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Paul I. <pi...@ot...> - 2003-10-13 17:23:34
|
Matthews <dem...@uw...> wrote: > Guard statements are lines like these in your header files: >=20 > #ifndef FOOHEADER_H > #define FOOHEADER_H >=20 > int foo; > char *foostring; > //... >=20 > #endif >=20 > Then if two files include foo.h, it won't be recompiled because FOOHEAD= ER_H > has already been defined. I think this answer is confusing to all the newbees out there... First point: Of course the header file will be compiled-in with each .cpp/.c that incl= udes=20 it. If you check the makefile, each .cpp is compiled by it self and there= is=20 no way for the compiler to know if the header has already been included a= nd=20 thus compiled... Second point: The guard statements mentioned prevent the same header from being include= d=20 more than once during the compilation of _one_ .cpp=B4. Consider the foll= owing: file1.h #include "file2.h" .... file2.h #include "file1.h" ... Without the guard stetements file1.h would include file2.h whitch include= s=20 file1.h...=20 Third point: The example .h-file above contains definitions of variables. If you inclu= de=20 this file the variables foo and foostring would be instanciated as local = (file- scope) in each .cpp where the .h is included. Not very useful?! To make g= lobal=20 variables declare as _external_ in header fil and move the instansiation = to=20 the .cpp file. Regards, Paul. |