On using complex.h RRS feed

  • Question

  • Hi guys,

    I'm currently working with Visual Studio 2012 with the Visual C++ compiler. My application is written in C and I'm using "/TC" for C code compilation.

    Now I saw that the new Visual Studio Version (2015 Communiy Edition) supports almost all C99 standards including complex numbers (complex.h), which I really do need for further developments. I installed the new version today and started with a pretty simple example I found on the internet:

    #include <stdlib.h>
    #include <math.h>
    #include <complex.h>

    int main()
        float f1 = 1.0;
        float complex fc = 2.0 + 3.0*I;
        // 4 Bytes
        printf("sizeof(float)         : %d\n", sizeof(float));
        // 8 Bytes (realer und imaginärer Teil)
        printf("sizeof(float complex) : %d\n",
            sizeof(float complex));
        // Ausgabe vom Real- und Imaginärteil
        printf("%f + %f\n", creal(fc), cimag(fc));
        return EXIT_SUCCESS;

    First of all, Visual studio indicates an error at variable "fc" (line 2 in main) in the source code. When I am trying to compile this example as a console application (x86), the compilation aborts with error C2146 (syntax error in line 2 in main).

    Can anyone help me with this problem? Searching the internet did not give any hints about that problem. For me, it seems the compiler can still not handle complex numbers?

    Thursday, October 15, 2015 1:24 PM