Initialization of complex types (C11)

When the C11 complex initialization feature is enabled, you can initialize C99 complex types with a value of the form x + yi, where x and y can be any floating point value, including Inf or NaN.

C onlyThe C11 complex initialization feature can be enabled by the -qlanglvl=extc1x group option.C only

C++ onlyThe C11 complex initialization feature can be enabled by the -qlanglvl=extended or -qlanglvl=extended0x group option. You can also use the -qlanglvl=complexinit suboption to enable this feature. When you specify the -qlanglvl=nocomplexinit option, only the C11 form of complex initialization is disabled.++ only

C onlyTo enable the initialization of these complex types, macros CMPLX, CMPLXF, and CMPLXL are defined inside the standard header file complex.h for C11 compilation, which act as if the following functions are used.

float complex CMPLXF( float x, float y );
double complex CMPLX( double x, double y );
long double complex CMPLXL( long double x, long double y );

Note: These macros might infringe upon user namespaces. You must avoid using the macro names for other purposes.
C only

These macros are available only if the C language header file complex.h is included, and they result in values that are suitable for static initialization if arguments are suitable for static initialization. C++ onlyTo use the C language header file complex.h in C++ programs, you must specify the -qlanglvl=c99complexheader or -qlanglvl=c99complex option.C++ only

The following example shows how to initialize a complex type with a value of the form x + yi.
// a.c
#include <stdio.h>
#include <math.h>
#include <complex.h>

int main(void) {
  float _Complex c = CMPLXF(5.0, NAN);
  printf("Value: %e + %e * I\n", __real__(c), __imag__(c));
  return;
}
You can specify the following command to compile this program:
xlc -qlanglvl=extc1x -qfloat=ieee a.c
The result of running the program is:
Value: 5 + NaNQ * I