Thread: [GD-General] Redundant Include Guards
Brought to you by:
vexxed72
From: Parveen K. <pk...@sf...> - 2002-12-16 02:26:37
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sticking with the theme of compile times. I'm reading Large-Scale C++ Software Design at the moment. The author recommends redundant include guards in .h files: // foo.h #ifndef _INCLUDE_FOO_H_ #define _INCLUDE_FOO_H_ #ifndef _INCLUDE_BAR_H_ #include "bar.h" #endif #ifndef _INCLUDE_VECTOR_ #include <vector> #define _INCLUDE_VECTOR_ #endif //// .... //// #endif So I tried this for a project of mine that consists of about 10KLOC. Compiling with gcc3.2 I saw no difference in compile times. Are compilers like gcc and msvc smart enough to figure stuff like this out? Or is my project just not large enough? The book was written way back in 1996, so I'm figuring some of the advice may be a little out of date. Parveen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQE9/Tnw6jdpm1dGc/cRAiCsAKCb2DuzooUpjSfzd3iFBDO9RexURgCeKHR6 uOTV9eicFER6so6dh5PJyJY= =nVAC -----END PGP SIGNATURE----- |
From: Dirk R. <ri...@ph...> - 2002-12-16 08:25:49
|
At least GCC is smart enough to prevent opening header files if they are guarded by include guard defines and when they are already parsed. Whether this applies to MSVC i do not know. Dirk -----Original Message----- From: gam...@li... [mailto:gam...@li...]On Behalf Of Parveen Kaler Sent: Monday, December 16, 2002 3:27 AM To: gam...@li... Subject: [GD-General] Redundant Include Guards -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sticking with the theme of compile times. I'm reading Large-Scale C++ Software Design at the moment. The author recommends redundant include guards in .h files: // foo.h #ifndef _INCLUDE_FOO_H_ #define _INCLUDE_FOO_H_ #ifndef _INCLUDE_BAR_H_ #include "bar.h" #endif #ifndef _INCLUDE_VECTOR_ #include <vector> #define _INCLUDE_VECTOR_ #endif //// .... //// #endif So I tried this for a project of mine that consists of about 10KLOC. Compiling with gcc3.2 I saw no difference in compile times. Are compilers like gcc and msvc smart enough to figure stuff like this out? Or is my project just not large enough? The book was written way back in 1996, so I'm figuring some of the advice may be a little out of date. Parveen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQE9/Tnw6jdpm1dGc/cRAiCsAKCb2DuzooUpjSfzd3iFBDO9RexURgCeKHR6 uOTV9eicFER6so6dh5PJyJY= =nVAC -----END PGP SIGNATURE----- ------------------------------------------------------- This sf.net email is sponsored by: With Great Power, Comes Great Responsibility Learn to use your power at OSDN's High Performance Computing Channel http://hpc.devchannel.org/ _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557 |
From: Arjen B. <arj...@ga...> - 2002-12-16 09:03:40
|
Not sure about that. It does have "#pragma once" though, which "specifies that the file, in which the pragma resides, will be included (opened) only once by the compiler in a build." Arjen Beij | AI Programmer Lost Boys Games | Prins Hendrikkade 139 | 1011AS Amsterdam The Netherlands Tel: +31 (0)20 4272277 | Fax: +31 (0)20 4274040 | arj...@ga... www.games.lostboys.com > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...]On Behalf Of > Dirk Ringe > Sent: Monday, December 16, 2002 09:27 > To: gam...@li... > Subject: RE: [GD-General] Redundant Include Guards > > > At least GCC is smart enough to prevent opening header files if they are > guarded by include guard defines and when they are already parsed. Whether > this applies to MSVC i do not know. > > Dirk |
From: Javier A. <ja...@py...> - 2002-12-16 08:26:37
|
gcc detects include guards automatically and will not reopen a guarded header, at least it used to... msvc has the #pragma once thing so I guess it doesn't autodetect guarded headers. That said, the first thing you want to do is structure your code and headers so that the number of header files included by other headers files (main source of re-includes) is minimal. Once you're there, redundant include guards buy you less and less. Parveen Kaler <pk...@sf...> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > > Sticking with the theme of compile times. > > I'm reading Large-Scale C++ Software Design at the moment. The author > recommends redundant include guards in .h files: > > So I tried this for a project of mine that consists of about 10KLOC. > Compiling with gcc3.2 I saw no difference in compile times. > > Are compilers like gcc and msvc smart enough to figure stuff like this > out? Or is my project just not large enough? The book was written > way back in 1996, so I'm figuring some of the advice may be a little > out of date. Javier Arevalo Pyro Studios |
From: Mick W. <mi...@ne...> - 2002-12-16 17:06:33
|
GCC does not need redundant include guards of the form you show below. Header files with internal guards will only be opened once. The only caveat is that you have to use the exact same path, including case, it you do something like: #include "header.h" then later in the same compilation unit. #include "sys\header.h" where they both refer to the same file, then it will get opened twice. This is not typically a big problem, just possibly confusing. Mick. > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...] On > Behalf Of Parveen Kaler > Sent: Sunday, December 15, 2002 6:27 PM > To: gam...@li... > Subject: [GD-General] Redundant Include Guards > > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Sticking with the theme of compile times. > > I'm reading Large-Scale C++ Software Design at the moment. > The author > recommends redundant include guards in .h files: > > // foo.h > #ifndef _INCLUDE_FOO_H_ > #define _INCLUDE_FOO_H_ > > > #ifndef _INCLUDE_BAR_H_ > #include "bar.h" > #endif > > #ifndef _INCLUDE_VECTOR_ > #include <vector> > #define _INCLUDE_VECTOR_ > #endif > > //// > .... > //// > > #endif > > So I tried this for a project of mine that consists of about 10KLOC. > Compiling with gcc3.2 I saw no difference in compile times. > > Are compilers like gcc and msvc smart enough to figure stuff > like this > out? Or is my project just not large enough? The book was > written way > back in 1996, so I'm figuring some of the advice may be a > little out of > date. > > Parveen > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.0.7 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iD8DBQE9/Tnw6jdpm1dGc/cRAiCsAKCb2DuzooUpjSfzd3iFBDO9RexURgCeKHR6 > uOTV9eicFER6so6dh5PJyJY= > =nVAC > -----END PGP SIGNATURE----- > > > > ------------------------------------------------------- > This sf.net email is sponsored by: > With Great Power, Comes Great Responsibility > Learn to use your power at OSDN's High Performance Computing > Channel http://hpc.devchannel.org/ > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557 > |