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

C99支持增加了Visual Studio 2013,但我无法在“C”代码中使用complex.h。

#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;
}

我收到语法错误。

编辑:对不起,缺少的部分。
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

最佳答案

如果一年后有人在搜索,请尝试
_Dcomplex dc1 = {3.0, 2.0};
用于变量声明。

通过查看VS2013的“complex.h” header ,似乎微软决定采用自己的C复数实现。您必须使用real()和imag()函数实现自己的算术运算符,即:

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

关于使用complex.h库在Visual Studio 2013中编译C代码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22991409/

10-11 23:05
查看更多