Re: Include guards and inclusion order
On 3 Dec., 00:43, Juha Nieminen <nos...@thanks.invalid> wrote:
Pete Becker wrote:
On 2007-12-01 21:38:27 -0500, Juha Nieminen <nos...@thanks.invalid> said:
Include guards are more or less mandatory so you shouldn't drop those.
(I don't really understand why the C++ standard can't simply state that
if a file is included more than once, only the first inclusion is taken
into account; I can't think of any use for multiple inclusion of the
same file in such way that its contents is parsed for each inclusion,
bar some really ugly obfuscated preprocessor trickery which nobody
really needs anyways.)
Read about <assert.h>.
I did, and I still can't understand why including <assert.h> several
times would make a difference.
And anyways, even if it did make a difference, wouldn't it be better
to simply have some kind of #pragma or whatever which tells the compiler
"it's ok to include this file more than once", the default behavior
being, when that #pragma does not appear, that multiple inclusions are
ignored?
I believe that what Pete Becker hinted at you was that the assert
macro might change behaviour underway: if you change the definition of
NDEBUG, a new inclusion of assert.h will redefine the assert-macro.
There are other uses that employes the fact that a new include of the
same file changes the meaning of the included source-code. A crude
implementation of templates spring to mind. You could define e.g.
std::vector via a macro and via some mechanism "instantiate" the
vector by including the macro.
I agree that it might have been a better idea to have some mechanism
to tell the compiler not to ignore a second include, but this should
have been changed loads of years ago, and such a solution is out of
the question today.
/Peter