Some shadow fixes.

Nathan Myers ncm@cantrip.org
Thu May 18 18:51:00 GMT 2000


On Thu, May 18, 2000 at 05:34:06PM -0700, Steven King wrote:
> On Thu, 18 May 2000, Nathan Myers wrote:
> 
> > Unfortunately, the standard requires that the ::abs visible when you 
> > include <math.h> be identically the same function as the std::abs.  
> > it also defines.  The same applies if somebody includes <cmath> 
> > and you later include <math.h>, or vice versa.
> > 
> > In practice, this means you have to hide the extern "C" declaration 
> > in a namespace somewhere, and define a single inline forwarding 
> > function to expose in various namespaces.  There are several examples 
> > of this in the shadow headers already; it seems we must use the same 
> > trick for the math functions too.  
> > 
> > Note, though, that the C++ standard doesn't include the C99 extensions,
> > so any such have to be guarded with #ifdef __USE_C9X.
> 
>   But the problem here is if you do
> 
> #include <stdlib.h>
> #include <math.h>
> 
> because of 7.3.3/9,  if we use a using directive, the abs in math wont be
> visable in the global namespace, or if we swap the inclusion order, vice
> versa (abs is overloaded in both cstdlib and cmath).

I think I see.  We need to put code in both headers, something like:

  #ifndef _CPP_ALREADY_EXPORTED_ABS
  # define _CPP_ALREADY_EXPORTED_ABS 1
    using std::abs;
  #endif

Normal name lookup will take care of the overloading, then.

Of course, that's 

  #ifdef __USE_C9X 
    ...  // other C9X-isms
  # ifndef _CPP_ALREADY_EXPORTED_ABS
  #   define _CPP_ALREADY_EXPORTED_ABS 1
      using std::abs;
  # endif
  #endif

in math.h.  Fortunately there's not much overloading
between C headers.

I wonder what we'll do about "clog"....  probably nothing.
(For those who don't know, C++ defines a standard output 
stream "clog", and the C9x committee in their infinite wisdom 
chose the same name for the complex logarithm.  Fortunately 
the C name is ::clog and the C++ name is std::clog.  The C
committee sentiment was summed up as, "You should have known 
better than to define any names that start with 'c'.")

Nathan Myers
ncm at cantrip dot org


More information about the Libstdc++ mailing list