使用 complex.h 库在 Visual Studio 2013 中编译 C 代码 [英] Compiling C code in Visual Studio 2013 with complex.h library

查看:21
本文介绍了使用 complex.h 库在 Visual Studio 2013 中编译 C 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

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(" ??? 
", 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

推荐答案

如果有人在一年后搜索,请尝试

In case anyone is searching a year later, try

_Dcomplex dc1 = {3.0, 2.0};

用于变量声明.

从 VS2013 的complex.h"标头内部来看,似乎微软决定了他们自己的 C 复数实现.您必须使用 real() 和 imag() 函数实现自己的算术运算符,即:

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

这篇关于使用 complex.h 库在 Visual Studio 2013 中编译 C 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆