This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Type name mangling


 
Martin wrote:
> Nathan wrote:
> > The C library subset of the standard C++ library offers good 
> > examples.  It defines a type, "struct tm".  C programmers are used 
> > to forward-declaring struct tags to use in declaring functions -- 
> > as in
> > 
> >   struct tm;
> >   void maraud(tm*);
> 
> I'm not sure I see the problem. While this style might be a C
> tradition, C++ programmers have learned to provide #include statements
> to access structure definitions - at least since ostream is a typedef.

Yes, the problem isn't in C++ code, it's in C headers used by
C++ code.  Suppose the above is in a C header.  That tm is not
the same tm as std::tm; the compiler hasn't even seen std::tm,
but it will happily mangle ::tm into maraud's name.

However, if in a different compilation unit <time.h> happens to
have been included first, then there is a global alias for 
std::tm, and then maraud will mangle differently.

Any actual tm objects are necessarily std::tm's, but pointers
passed to maraud might be either.  The compiler will need to be 
able to accommodate that.

C programmers are not going to give up their forward struct 
declarations.   (A lot of them still like implicit int.)
 
> So the problem really is with placing namespace std into <ctime>,
> right? This is but one of the transition problems related to namespace
> introduction, where the transition from <iostream.h> to <iostream> is
> much more serious. 

Namespace std in <ctime> is an example of the problem, but
it's much more widespread.
 
> Users have come to accept that the ABI breaks between compiler
> versions. I doubt they would accept a language change as serious as
> the one you propose, if the current standard is not even completely
> implemented by most compilers.

Users will not continue accepting ABI breakage, and such breakage is 
impeding acceptance of C++.  Eventually we will have to settle 
down and make some promises, but first we need something like
conformance. 

Anyway, I'm not proposing a language change, only a compiler change, 
to become part of -fnew-abi.  A change like this appears necessary to 
shoehorn the C headers into namespace std and still be able to
use C libraries.  If users cannot link to C libraries without
-fno-honor-std, we will have failed.

Nathan Myers
ncm@cantrip.org



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]