This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 3.0 cannot compile pooma
- To: Benjamin Kosnik <bkoz at redhat dot com>
- Subject: Re: gcc 3.0 cannot compile pooma
- From: "Zack Weinberg" <zackw at Stanford dot EDU>
- Date: Wed, 6 Jun 2001 16:30:04 -0700
- Cc: Gabriel Dos Reis <gdr at codesourcery dot com>, gcc at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
On Wed, Jun 06, 2001 at 03:50:06PM -0700, Benjamin Kosnik wrote:
> > It's not at all clear to me what the c_shadow headers are trying to do
> > or why they don't work. However, closing namespaces and extern "C"
> > blocks at the _beginning_ of a header and opening them at the _end_
> > looks, at the very least, impossibly fragile.
>
> the extern "C" bits have to go. They add needless complexity: a patch
> that removed them (in both math.h and bits/std_cmath.h in the c_shadow
> directory) can be considered pre-approved.
>
> The namespace trickery has to remain, however.
It seems to me that something like this should do just as well and be
less fragile.
/* cstdlib */
#ifndef _GLIBCPP_CSTDLIB
#define _DONT_IMPORT_EVERYTHING
#include <stdlib.h>
#endif /* <cstdlib> */
---
/* stdlib.h */
#ifndef _GLIBCPP_STDLIB_H
namespace _C_stdlib_h {
#include_next "stdlib.h"
}
#ifndef _DONT_IMPORT_EVERYTHING
using namespace _C_stdlib_h;
#endif
#undef _DONT_IMPORT_EVERYTHING
namespace std {
#undef strcpy
/* ... */
using ::_C_stdlib_h::strcpy;
/* ... */
#ifndef __size_t_in_namespace_std
typedef ::_C_stdlib_h::size_t size_t;
#define __size_t_in_namespace_std
#endif
/* ... */
};
#endif
---
The separate internal namespaces for each C header are because you
don't want to drag in everything from _every_ C header just because
the user asked for everything from _one_ C header.
Note that if this works, then I don't think it's necessary to provide
shadows for C headers not specified by C++98, which makes life
considerably simpler.
Note2, that in this scheme, nonstandard typedefs in a C header will
only be aliased into the global namespace by the shadow header. I
don't see any way around that and I think Nathan's scheme has the same
problem.
Note3, that if you liked, we could add some kind of namespace support
to the preprocessor, which could make life a lot simpler. (E.g.
#pragma GCC prefix __foobar_ would tack __foobar_ on the beginning of
every macro defined until the next #pragma GCC prefix. This is
probably too simple, but you get the idea.)
--
zw The beginning of almost every story is actually a bone, something with
which to court the dog, which may bring you closer to the lady.
-- Amos Oz, _The Story Begins_