Topic: Multiple inclusion of standard headers?


Author: David Svoboda <svoboda@cert.org>
Date: Wed, 3 Jun 2009 16:51:30 CST
Raw View
C99 S7.1.2 "Standard Headers", says:
> Standard headers may be included in any order; each may be included more than once in
> a given scope, with no effect different from being included only once, except that the
> effect of including <assert.h> depends on the definition of NDEBUG (see 7.2).

So a program that has two lines that say "#include <stdio.h>" is no
worse than the same program with one of those lines removed.


My question is: I can't find anything in C++2003 that makes the same
guarantee. So does standard C++ actually guarantee this or not? Does
it 'inherit' this property from C99?

--
David Svoboda <svoboda@cert.org>
Software Security Engineer
CERT Secure Coding
(412) 268-3965

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Pete Becker <pete@versatilecoding.com>
Date: Wed, 3 Jun 2009 17:44:34 CST
Raw View
David Svoboda wrote:
>
> C99 S7.1.2 "Standard Headers", says:
>> Standard headers may be included in any order; each may be included
>> more than once in
>> a given scope, with no effect different from being included only once,
>> except that the
>> effect of including <assert.h> depends on the definition of NDEBUG
>> (see 7.2).
>
> So a program that has two lines that say "#include <stdio.h>" is no
> worse than the same program with one of those lines removed.
>
>
> My question is: I can't find anything in C++2003 that makes the same
> guarantee. So does standard C++ actually guarantee this or not? Does
> it 'inherit' this property from C99?
>

[lib.using.headers]/2.

--
    Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Thu, 4 Jun 2009 21:26:55 CST
Raw View
On 4 Jun., 00:51, David Svoboda <svob...@cert.org> wrote:
> C99 S7.1.2 "Standard Headers", says:
>
> > Standard headers may be included in any order; each may be included more than once in
> > a given scope, with no effect different from being included only once, except that the
> > effect of including <assert.h> depends on the definition of NDEBUG (see 7.2).
>
> So a program that has two lines that say "#include <stdio.h>" is no
> worse than the same program with one of those lines removed.
>
> My question is: I can't find anything in C++2003 that makes the same
> guarantee. So does standard C++ actually guarantee this or not? Does
> it 'inherit' this property from C99?

This guarantee is already present in C++03 in 17.4.2.1
[lib.using.headers]/2:

"A translation unit may include library headers in any order (clause
2).
Each may be included more than once, with no effect different from
being
included exactly once, except that the effect of including either
<cassert>
or <assert.h> depends each time on the lexically current definition
of
NDEBUG.161)"

Note the slight modification to ensure that <cassert> behaves equal to
<assert.h>.

Greetings from Bremen,

Daniel Kr   gler


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]