[patch] Better NAN definition for more recent GCC

Joseph S. Myers joseph at codesourcery.com
Wed Jan 4 17:48:00 UTC 2006

The definition of NAN in libc/sysdeps/linux/common/bits/nan.h is not a 
constant expression (suitable for static initializers) as required by C99.  
More recent GCC versions provide __builtin_nanf which can be used for this 
purpose; this patch merges the relevant changes from glibc to use 
__builtin_nanf.  (There are similar built-in functions for INFINITY, 
HUGE_VAL etc.; though there the hex float constants presently used do 
work, albeit with warnings; again the relevant changes are in current 

Index: libc/sysdeps/linux/common/bits/nan.h
--- libc/sysdeps/linux/common/bits/nan.h	(revision 13080)
+++ libc/sysdeps/linux/common/bits/nan.h	(working copy)
@@ -24,8 +24,12 @@
 /* IEEE Not A Number.  */
-#ifdef	__GNUC__
+#if __GNUC_PREREQ(3,3)
+# define NAN	(__builtin_nanf(""))
+#elif defined __GNUC__
 # define NAN \
   (__extension__                                                            \
    ((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; })  \

Joseph S. Myers
joseph at codesourcery.com

More information about the uClibc mailing list