[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Does cstdlib pollute the global namespace?

From: Pedro Lamarão
Subject: Re: Does cstdlib pollute the global namespace?
Date: Thu, 18 Oct 2007 19:07:46 -0000
User-agent: G2/1.0

On Oct 18, 2:58 pm, Jeff Schwab <> wrote:
> Is the following error message correct?  It seems like system() ought
> to be in the ::std namespace.  What am I missing?
>     //
>     #include <cstdlib>
>     namespace system { }
>     $ g++ -ansi -pedantic -Wall -c
> error: 'namespace system { }' redeclared as different
> kind of symbol
>     /usr/include/stdlib.h:738: error: previous declaration of 'int
> system(const char*)'
>     make: *** [main.o] Error 1
> My current work-around is an unnamed "wrapper" namespace:
>     namespace { namespace system { } }

This behaviour is alloweb by the Standard.

In the section [headers] paragraph 4 of the current draft we read:

"Except as noted in clauses 18 through 27 and Annex D the contents of
each header cname shall be the same as that of
the corresponding header name.h, as specified in the Standard C99
Library (1.2) or the C Unicode TR, as appropriate, as
if by inclusion. In the C++ Standard Library, however, the
declarations (except for names which are defined as macros
in C) are within namespace scope (3.3.5) of the namespace std. It is
unspecified whether these names are first declared
within the global namespace scope and are then injected into namespace
std by explicit using-declaration s (7.3.3)."

That last sentence means the compiler is allowed to declare these
names in the global namespace.

I don't have the current Standard around to check if the same language
is in place, but I believe it to be so.

 Pedro Lamarão

reply via email to

[Prev in Thread] Current Thread [Next in Thread]