12

http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-library-support-in-visual-studio-2013.aspx

C99 support added visual studio 2013, but I cant use complex.h in my "C" code.

#include <stdio.h>
#include <complex.h>
int main(void)
{
    double complex dc1 = 3 + 2 * I;
    double complex dc2 = 4 + 5 * I;
    double complex result;

    result = dc1 + dc2;
    printf(" ??? \n", result);

    return 0;
}

I get syntax errors.

Edit: Sorry for the missing part.

error C2146: syntax error : missing ';' before identifier 'dc1'
error C2065: 'dc1' : undeclared identifier
error C2088: '*' : illegal for struct
error C2086: 'double complex' : redefinition
error C2146: syntax error : missing ';' before identifier 'dc2'
error C2065: 'dc2' : undeclared identifier
error C2088: '*' : illegal for struct
error C2086: 'double complex' : redefinition
error C2146: syntax error : missing ';' before identifier 'result'
error C2065: 'result' : undeclared identifier
error C2065: 'result' : undeclared identifier
error C2065: 'dc1' : undeclared identifier
error C2065: 'dc2' : undeclared identifier
error C2065: 'result' : undeclared identifier           
IntelliSense: expected a ';'
IntelliSense: expected a ';'
IntelliSense: expected a ';'
IntelliSense: identifier "result" is undefined
IntelliSense: identifier "dc1" is undefined
IntelliSense: identifier "dc2" is undefined
4
  • And where do you get these sysntax errors ? Apr 10, 2014 at 14:46
  • 7
    When you post a question regarding errors, then it's very helpful to include the actual errors (complete and unedited) in the question. Please edit your question to include the errors. Apr 10, 2014 at 14:48
  • 5
    It seems that the support for complex is not as complete as the blog-post tells us it is. Apr 11, 2014 at 6:46
  • pretty unfortunate that VS has such bad support for more modern versions of C Jun 11, 2019 at 17:40

2 Answers 2

15

In case anyone is searching a year later, try

_Dcomplex dc1 = {3.0, 2.0};

for the variable declaration.

From looking inside VS2013's "complex.h" header, it seems that Microsoft decided on their own implementation for C complex numbers. You'll have to implement your own arithmetical operators using the real() and imag() functions, i.e.:

double real_part = real(dc1) + real(dc2);
double imag_part = imag(dc1) + imag(dc2);
_Dcomplex result = {real_part, imag_part};
2

Another way is to define like:

/*_Fcomplex */  _C_float_complex a =  _FCbuild(5.0F, 1.0F);    
printf( "z = %.1f% + .1fi\n", crealf(a), cimagf(a));    

/*_Dcomplex*/ _C_double_complex b = _Cbuild(3.0, 2.0);    
printf("z = %.1f% + .1fi\n",creal(b), cimag(b));    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.