This is the mail archive of the
libstdc++@sources.redhat.com
mailing list for the libstdc++ project.
[c++] builtin functions and namespaces
- To: gcc <gcc at gcc dot gnu dot org>
- Subject: [c++] builtin functions and namespaces
- From: brent verner <brent at rcfile dot org>
- Date: Fri, 1 Sep 2000 19:09:59 -0400
- Cc: stdc++ <libstdc++ at sourceware dot cygnus dot com>
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_