This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Make math.h FP_* macros usable in #if (bug 3439)


Bug 3439 is the failure of certain macros in math.h and fenv.h to be
usable in #if expressions, contrary to the ISO C rule that "All
object-like macros listed as expanding to integer constant expressions
shall additionally be suitable for use in #if preprocessing
directives.".

In past discussion of this issue it's been concluded that any solution
need to avoid repeating the numeric value of each constant more than
once, while it's also useful to keep the enum definitions (rather than
just having macro definitions) so that the values are available from
debuggers without needing to build with -g3.  So the macro definition
containing the constant needs to be used in some way to set the enum
value.

This patch fixes the constants in math.h following the approach
suggested by Paul Eggert in comment#8 on that bug.  If people don't
like that approach, hopefully another approach can be agreed (for this
header, fenv.h and any other cases that may be found as the conform/
data is made to reflect ISO C requirements more precisely).

Tested x86_64.  This removes some conform/ failures for the various
standards based on C99.

2012-11-02  Joseph Myers  <joseph@codesourcery.com>

	[BZ #3439]
	* math/math.h (FP_NAN): Define macro to integer constant usable in
	#if and use that to give value to enum constant.
	(FP_INFINITE): Likewise.
	(FP_ZERO): Likewise.
	(FP_SUBNORMAL): Likewise.
	(FP_NORMAL): Likewise.

diff --git a/math/math.h b/math/math.h
index bcdd5c9..0b4bc0c 100644
--- a/math/math.h
+++ b/math/math.h
@@ -189,16 +189,21 @@ extern int signgam;
 /* All floating-point numbers can be put in one of these categories.  */
 enum
   {
-    FP_NAN,
-# define FP_NAN FP_NAN
-    FP_INFINITE,
-# define FP_INFINITE FP_INFINITE
-    FP_ZERO,
-# define FP_ZERO FP_ZERO
-    FP_SUBNORMAL,
-# define FP_SUBNORMAL FP_SUBNORMAL
-    FP_NORMAL
-# define FP_NORMAL FP_NORMAL
+    FP_NAN =
+# define FP_NAN 0
+      FP_NAN,
+    FP_INFINITE =
+# define FP_INFINITE 1
+      FP_INFINITE,
+    FP_ZERO =
+# define FP_ZERO 2
+      FP_ZERO,
+    FP_SUBNORMAL =
+# define FP_SUBNORMAL 3
+      FP_SUBNORMAL,
+    FP_NORMAL =
+# define FP_NORMAL 4
+      FP_NORMAL
   };
 
 /* Return number of classification appropriate for X.  */

-- 
Joseph S. Myers
joseph@codesourcery.com


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