On 10/24/10, Philip Guenther <[email protected]> wrote:
> On Sat, 23 Oct 2010, Landry Breuil wrote:
>> i'm porting an app which uses:
>> static gdouble line_speed = NAN;
>> static gdouble line_course = NAN;
>>
>> which yields:
>> gpspoint.c:84: error: initializer element is not constant
>> gpspoint.c:85: error: initializer element is not constant
>>
>> Kirill Bychkov pointed out
>> (http://marc.info/?l=openbsd-ports&m=128645629406557&w=2)
>> to me that netbsd had the following related pr which affects us too:
>> http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=40695
>>
>> Can we consider using the same libc fix ?
>
> I'm with Mike in not seeing the benefit of the linker warning, especially
> if the math.h change still uses __nan for the non-GCC case, or rather for
> the not-gcc-3.3-or-newer case. The gcc2 platforms will obviously continue
> to be non-compliant. ok guenther@ on the math.h bit.
actually, c99 requires all of those macros expand to the constant expressions.
- make HUGE_VAL, HUGE_VALF, HUGE_VALL, INFINITY, NAN expand to the
constant expressions with the help of gcc post-3.3.
i'm attaching the diff below with hope that gmail doesn't mangle it.
alternatively, you can find it on cvs:~martynas.
Index: math.h
===================================================================
RCS file: /cvs/src/include/math.h,v
retrieving revision 1.26
diff -u -r1.26 math.h
--- math.h 25 Jul 2009 11:38:09 -0000 1.26
+++ math.h 24 Oct 2010 00:07:47 -0000
@@ -25,7 +25,11 @@
* ANSI/POSIX
*/
extern char __infinity[];
+#if __GNUC_PREREQ__(3, 3)
+#define HUGE_VAL __builtin_huge_val()
+#else /* __GNUC_PREREQ__(3, 3) */
#define HUGE_VAL (*(double *)(void *)__infinity)
+#endif /* __GNUC_PREREQ__(3, 3) */
/*
* C99
@@ -34,6 +38,12 @@
typedef __double_t double_t;
typedef __float_t float_t;
+#if __GNUC_PREREQ__(3, 3)
+#define HUGE_VALF __builtin_huge_valf()
+#define HUGE_VALL __builtin_huge_vall()
+#define INFINITY __builtin_inff()
+#define NAN __builtin_nanf("")
+#else /* __GNUC_PREREQ__(3, 3) */
#ifdef __vax__
extern char __infinityf[];
#define HUGE_VALF (*(float *)(void *)__infinityf)
@@ -46,6 +56,7 @@
extern char __nan[];
#define NAN (*(float *)(void *)__nan)
#endif /* !__vax__ */
+#endif /* __GNUC_PREREQ__(3, 3) */
#define FP_INFINITE 0x01
#define FP_NAN 0x02