This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
RE: C headers and std namespace
- To: <libstdc++ at sourceware dot cygnus dot com>
- Subject: RE: C headers and std namespace
- From: "Anthony Williams" <anthony_w dot geo at yahoo dot com>
- Date: Wed, 12 Apr 2000 09:43:39 +0100
- Reply-To: "Anthony Williams" <anthony at anthonyw dot cjb dot net>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I have a fix to the problem I reported a few days ago regarding the
<cctype> header and 'using namespace std;'
To recap the problem:
With sparc-solaris-2.7 versions of gcc-2.95.2 and libstdc++-2.90.8
snapshot, the following code produces ambiguity errors:
#include <cctype>
using namespace std;
int main()
{
char a='A';
if(isdigit(a))
return 0;
return 1;
}
ambiguity: isdigit(char) could be ::isdigit(int) or std::isdigit(int)
Fix:
Modify bits/std_cctype.h as follows:
Add #include <bits/stl_config.h> to the top
Change "namespace std{" to "__STL_BEGIN_NAMESPACE"
Change the matching "}" to "__STL_END_NAMESPACE"
Move the "#include_next <ctype.h>" inside the namespace
Remove all the #elif _GLIBCPP_USE_NAMESPACES sections
Here are the diffs:
diff std_cctype.h.orig std_cctype.h
42c42
< # include_next <ctype.h>
- ---
> #include <bits/stl_config.h>
48,51c48
< namespace std
< {
< // NB: If not using namespaces, can't have any of these
definitions,
< // as they will duplicate what's in the global namespace.
- ---
> __STL_BEGIN_NAMESPACE
52a50,51
> # include_next <ctype.h>
>
59,61d57
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< toupper(int __c) { return ::toupper(__c); }
70,72d65
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< tolower(int __c) { return ::tolower(__c); }
81,83d73
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< isspace(int __c) { return ::isspace(__c); }
92,94d81
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< isprint(int __c) { return ::isprint(__c); }
103,105d89
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< iscntrl(int __c) { return ::iscntrl(__c); }
114,116d97
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< isupper(int __c) { return ::isupper(__c); }
125,127d105
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< islower(int __c) { return ::islower(__c); }
136,138d113
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< isalpha(int __c) { return ::isalpha(__c); }
147,149d121
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< isdigit(int __c) { return ::isdigit(__c); }
158,160d129
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< ispunct(int __c) { return ::ispunct(__c); }
169,171d137
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< isxdigit(int __c) { return ::isxdigit(__c); }
180,182d145
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< isalnum(int __c) { return ::isalnum(__c); }
191,193d153
< #elif _GLIBCPP_USE_NAMESPACES
< inline int
< isgraph(int __c) { return ::isgraph(__c); }
196c156
< } // namespace std
- ---
> __STL_END_NAMESPACE
Now, all macros are replaced with inline functions, and everything is
in the std:: namespace (if __STL_BEGIN_NAMESPACE says so)
Anthony
alink@anthonyw.cjb.net -- Questions relating to ALINK
anthony@anthonyw.cjb.net -- Non-ALINK questions
http://anthonyw.cjb.net/ -- ALINK home page
PGP Fingerprint:
0E2D D32A 8732 DC31 804C D435 9BF0 F8FE 1C1B 9AD5
PGP Key at: http://i3.yimg.com/3/c7e5ee24/g/68fc2307.asc
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.1 for non-commercial use <http://www.pgp.com>
iQA/AwUBOPQ3Opvw+P4cG5rVEQJfiQCg63jIXgI4uyE9nHhzaLD32N+njvMAoOul
pRbdr+9he00Pb5YTwOC6KSdC
=cZfc
-----END PGP SIGNATURE-----
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com