This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: namespace issues with old C headers
On Mon, Apr 14, 2003, Loren James Rittle wrote:
> > I agree that none of my proposals were perfect; that is why I
> > posted three of them. Is Loren working on a patch other than the
> > one he mentioned in this thread?
>
> The patches I'm currently working on relate to system header name
> visibility (i.e. as keyed off well-known, sometimes standard-defined,
> macros) and mirroring same as best as possible in libstdc++-v3 for all
> ports (my main port of interest is *-*-freebsd* but I'm trying for a
> semi-generic solution).
>
> Agreed, I don't think I'm solving the C99 / C++98 conflict issue under
> discussion in this thread. I think practical concerns are what drove
> us to attempt to support as much of C99 as possible in libstdc++-v3
> even if not encouraged by C++98. If there are cases where a program
> can't use the classic headers along with C++ headers, then IMHO it is
> the job of our C++ library implementation to address the conflict.
Right. This doesn't solve the problem I'm asking about, and I
didn't expect that it would. However, I'm glad you're doing it
because I think it's important nevertheless. Thanks!
> Also, David, I'm confused. Could you repost an exact test case that
> now fails. g++ with libstdc++-v3 built on ref5/beast after you
> updated C99 stuff in the system headers appears to handle:
>
> #include <cstdlib>
> #include <cmath>
> #include <math.h>
>
> main()
> {
> using namespace std;
> double a = 0.0;
> double b = NAN;
> double c = 1.0;
>
> if (FP_ZERO != fpclassify (a)) abort ();
> if (FP_NAN != fpclassify (b)) abort ();
> if (FP_NORMAL != fpclassify (c)) abort ();
> }
>
> For the moment, users attempting to compile code at the confluence of
> C99 and C++98, will have to deal with adding the 'using namespace std'
> or 'using std::fpclassify'.
The problem is exactly what you mention in your last paragraph:
programs expecting fpclassify(), isnan(), and friends to appear
in the global namespace after including math.h will not compile.
Try the above without the 'using namespace std;'.
Note that things work fine if <math.h> is included without
<cmath>, but if <cmath> is ever included directly or indirectly,
it removes the global C99 macros. This is a regression over
previous behavior; when isnan() was defined as a function
previously, it worked just fine.
It's actually a little more broken than that in FreeBSD right now,
since _GLIBCPP_USE_C99 is not defined. The patch below fixes that
and other things, but still doesn't address the problem described
above.
Index: gnu/lib/libstdc++/c++config.h
===================================================================
RCS file: /cvs/src/gnu/lib/libstdc++/c++config.h,v
retrieving revision 1.3
diff -u -r1.3 c++config.h
--- gnu/lib/libstdc++/c++config.h 19 Feb 2003 04:28:12 -0000 1.3
+++ gnu/lib/libstdc++/c++config.h 31 Mar 2003 22:51:16 -0000
@@ -101,7 +101,7 @@
#define _GLIBCPP_USE_LONG_LONG 1
// Define if C99 features such as lldiv_t, llabs, lldiv should be exposed.
-/* #undef _GLIBCPP_USE_C99 */
+#define _GLIBCPP_USE_C99 1
// Define if code specialized for wchar_t should be used.
/* #undef _GLIBCPP_USE_WCHAR_T */
@@ -649,10 +649,10 @@
/* #undef _GLIBCPP_HAVE_SQRTL */
/* Define if you have the strtof function. */
-/* #undef _GLIBCPP_HAVE_STRTOF */
+#define _GLIBCPP_HAVE_STRTOF 1
/* Define if you have the strtold function. */
-/* #undef _GLIBCPP_HAVE_STRTOLD */
+#define _GLIBCPP_HAVE_STRTOLD 1
/* Define if you have the swprintf function. */
#define _GLIBCPP_HAVE_SWPRINTF 1
@@ -748,7 +748,7 @@
#define _GLIBCPP_HAVE_WCSTOD 1
/* Define if you have the wcstof function. */
-/* #undef _GLIBCPP_HAVE_WCSTOF */
+#define _GLIBCPP_HAVE_WCSTOF 1
/* Define if you have the wcstok function. */
#define _GLIBCPP_HAVE_WCSTOK 1
@@ -832,7 +832,7 @@
#define _GLIBCPP_HAVE_SYS_RESOURCE_H 1
/* Define if you have the <sys/stat.h> header file. */
-/* #undef _GLIBCPP_HAVE_SYS_STAT_H */
+#define _GLIBCPP_HAVE_SYS_STAT_H 1
/* Define if you have the <sys/types.h> header file. */
#define _GLIBCPP_HAVE_SYS_TYPES_H 1
Index: gnu/lib/libstdc++/config.h
===================================================================
RCS file: /cvs/src/gnu/lib/libstdc++/config.h,v
retrieving revision 1.4
diff -u -r1.4 config.h
--- gnu/lib/libstdc++/config.h 19 Feb 2003 04:28:12 -0000 1.4
+++ gnu/lib/libstdc++/config.h 31 Mar 2003 13:53:19 -0000
@@ -13,7 +13,7 @@
#define _GLIBCPP_USE_LONG_LONG 1
// Define if C99 features such as lldiv_t, llabs, lldiv should be exposed.
-/* #undef _GLIBCPP_USE_C99 */
+#define _GLIBCPP_USE_C99 1
// Define if code specialized for wchar_t should be used.
/* #undef _GLIBCPP_USE_WCHAR_T */
@@ -561,10 +561,10 @@
/* #undef HAVE_SQRTL */
/* Define if you have the strtof function. */
-/* #undef HAVE_STRTOF */
+#define HAVE_STRTOF 1
/* Define if you have the strtold function. */
-/* #undef HAVE_STRTOLD */
+#define HAVE_STRTOLD 1
/* Define if you have the swprintf function. */
#define HAVE_SWPRINTF 1
@@ -660,7 +660,7 @@
#define HAVE_WCSTOD 1
/* Define if you have the wcstof function. */
-/* #undef HAVE_WCSTOF */
+#define HAVE_WCSTOF 1
/* Define if you have the wcstok function. */
#define HAVE_WCSTOK 1