[c++] builtin functions and namespaces
brent verner
brent@rcfile.org
Fri Sep 1 16:10:00 GMT 2000
Hi,
The code below, representative of what is necessary for std compliant
c headers, does not compile w/o the '-fno-builtin' being passed to g++.
This is due to abs being a builtin function in the compiler. The
_initially obvoius_ solution is to have g++ default to -fno-builtin
whenever --enable-cshadow-headers is requested. What side-effects to
a default of -fno-builtin am I _not seeing_? Shouldn't the compiler be
able to recognize _in which namespace_ its builtin function is being
requested/declared?
Compiling this causes the complaint that abs(int) is ambiguous:
abs(int)
&&
std::abs(int)
however, commenting out the 'using namespace std;' line, the complaint
is that abs(int) is _undeclared_. Now, forgive me for not understanding
enough of this, but, for the original ambiguity to exist, didn't
abs(int) have to be declared? How did removing the using directive, also
take away the delcaration of abs(int)? Why is the builtin being declared
in the global namespace _only_ when it is visible via another exposed
namespace? (forgive me if my terminology is wrong).
namespace _C_ {
extern "C" {
extern int puts(const char*);
extern int abs(int a);
}
}
namespace std {
using ::_C_::puts;
using ::_C_::abs;
}
using namespace std;
int
main()
{
puts("yup");
abs(1);
}
thanks,
Brent
--
Damon Brent Verner o _ _ _
Cracker Jackî Surprise Certified _o /\_ _ \\o (_)\__/o (_)
brent@rcfile.org _< \_ _>(_) (_)/<_ \_| \ _|/' \/
brent@linux1.org (_)>(_) (_) (_) (_) (_)' _\o_
More information about the Libstdc++
mailing list