[Bug libstdc++/6257] C-library symbols enter global namespace

marc dot glisse at normalesup dot org gcc-bugzilla@gcc.gnu.org
Tue Apr 18 15:10:00 GMT 2006



------- Comment #17 from marc dot glisse at normalesup dot org  2006-04-18 15:10 -------
(In reply to comment #15)
> So there's a problem with the multiple-include-protection in glibc!

Yes, the way it is done in solaris is way more convenient. There, stdlib.h
includes a file iso/stdlib_iso.h that has all the meat, and then stdlib.h does
all the using std::foo; stuff, so cstdlib can just include iso/stdlib_iso.h
directly. On solaris, I get quite satisfactory results with:
g++ -I/opt/SUNWspro/prod/include/CC/std -D__cplusplus=199711L -U__EXTENSIONS__
-D__STDC__=0
(the include directory contains the cstd headers from sunpro, but they are just
one or 2 #include lines)

> But we can't do this in any manner because they have multiple-include
> protection which can't tell the difference.

gcc could come with its own stdlib.h. Both this stdlib.h and cstdlib would
include /usr/include/stdlib.h (always with _GLIBCPP_USE_NAMESPACES) and the gcc
provided stdlib.h would additionally contain the appropriate using std::foo;
lines. The 2 problems I see with this approach are:
1) it means having 2 files with the same name in the search path, and inclusion
of the glibc file has to be done with an explicit path of /usr/include (or some
other compile time constant)
2) This will do what we want for standard functions, but what about extensions
that are declared in stdlib.h in glibc (protected by __USE_ISOC99 or __USE_GNU
for example), what happens to them? It might work well, I have not tested.

> At the beginning of stdio.h, instead of:
> #ifndef _STDIO_H
> #define _STDIO_H
> we would have:
> #if   ( ( defined __cplusplus && defined _GLIBCPP_USE_NAMESPACES ) \
>         && ! defined _STDIO_H_WITH_NAMESPACES ) \
>    || ( (! defined __cplusplus || ! defined _GLIBCPP_USE_NAMESPACES )\
>         && ! defined _STDIO_H )
> #if defined __cplusplus && defined _GLIBCPP_USE_NAMESPACES
> #  define _STDIO_H_WITH_NAMESPACES
> #else
> #  define _STDIO_H
> #endif

This way you get 2 declarations instead of one and a using directive, I am not
sure it won't cause problems (but I don't know).


-- 

marc dot glisse at normalesup dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marc dot glisse at
                   |                            |normalesup dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=6257



More information about the Gcc-bugs mailing list