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


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

Re: Where is C++'s math.h's double abs(double)?


Ross Smith <ross.s@ihug.co.nz> writes:

| Gabriel Dos Reis wrote:
| > 
| > | " Each C header, whose name has the form name.h, behaves as if each name
| > | placed in the Standard library namespace by the corresponding cname header is
| > | also placed within the namespace scope of the name-space std and is followed
| > | by an explicit using-declaration (7.3.3) 3
| 
| Using declarations import names, not specific overloads.

But unlike a using-directive, name lookup won't find overloaded
declaration introduced later.


| .... It follows that
| all overloads of a function declared in namespace std in <cmath> also
| appear in the global namespace in <math.h>.

Not at all.

	#include <stdio.h>

	namespace X
	{
	    void f(int)
	    {
	       printf("f(int)\n");
	    }
	}

	using X::f;

	void g(double x)
	{
	    f(x);
	}

	namespace X	// #1
	{
	    void f(double)
	    {
		printf("f(double)\n");
	    }
	}

	int main()
	{
	   g(1.0);
	}

	
The specific point here is that the line #1 corresponds to what is
done to comply with the exceptional cases introduced cited below. 

| > 26.5/2
| > 
| >    The contents of these headers [<cmath> and <cstdlib>] are the same
| >    as the Standard C library headers <math.h> and <stdlib.h>, with the
| >    following additions:

-- Gaby


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