How can I determine if _Complex_I is defined in complex.h?

Dr. David Kirkby david.kirkby@onetel.net
Fri Jul 30 13:42:00 GMT 2010


I wish to determine if _Complex_I is defined in complex.h or not. On some 
versions of Solaris it is, on others it is not.

Here's a bit of test code

drkirkby@hawk:~$ cat test.c
#include <stdio.h>
#include <complex.h>

/*
  * "volatile" is meant to prevent gcc from calculating the sqrt as a
  * constant, we want to test libc.
  */
volatile complex double z = -_Complex_I;
int
main(void)
{
         z = csqrt(z);
         if (creal(z) > 0.0)
                 printf("good\n");       /* good */
         else
                 printf("bad\n");       /* bad */
}

On some versions of Solaris/OpenSolaris this compiles fine, but others it does 
not - see below. Rather surprising, it does appear to be defined on a Solaris 
released in 2008, but not ones earlier (2005) or later (2009).

What is the simplest way to test for this - ideally in a script, without needing 
to compile anything and so write files?

Dave


// OpenSolaris 06/2009 x64 hardware
drkirkby@hawk:~$ gcc -lm test.c
test.c:8: error: '_Complex_I' undeclared here (not in a function)

// Solaris 10 on x86 05/2008
64 drkirkby@fulvia:[~] $ gcc -lm test.c
64 drkirkby@fulvia:[~] $ ./a.out
good


// Solaris 10 on SPARC March 2005 release
64 drkirkby@redstart:[~] $ gcc test.c
test.c:8: error: '_Complex_I' undeclared here (not in a function)

// Solaris 10 on SPARC May 2009 release
kirkby@t2:[~] $ gcc -lm test.c
test.c:8: error: ‘_Complex_I’ undeclared here (not in a function)
kirkby@t2:[~] $ cat /etc/release





More information about the Gcc-help mailing list