gpt4 book ai didi

c - 如何在 Windows 上通过 clang 使用 C99 复数?

转载 作者:太空宇宙 更新时间:2023-11-04 07:45:43 26 4
gpt4 key购买 nike

我已经安装了 Visual Studio 2019,它随附了 clang。我可以使用 clang 成功编译和链接应用程序.

当我 #include <complex.h>但是,我没有得到符合标准的复数。

这是一个在包含 <complex.h> 后不起作用的示例.

complex float z = 2.0f + 3.0f * I;

它告诉我 complex关键字未声明。

error: use of undeclared identifier 'complex'

但是,我可以使用 Microsoft 非标准复数。这是一个完整的有效程序。

#include <stdio.h>
#include <complex.h>

int main( int argc, char *argv[] ) {
_Fcomplex z = { 2.0f, 3.0f };

printf( "z = %f + %f * i\n", crealf( z ), cimagf( z ) );
return 0;
}

而且我可以用 clang -m64 -o cmplx.exe cmplx.c 编译和链接它.输出是可预测的

z = 2.000000 + 3.000000 * i

我可以在 Windows 上使用 clang 获得符合标准的复数吗?

最佳答案

编译器和它使用的库是分开的。即使您使用 clang 进行编译,you're still using Microsoft's non-standard libraries .

The Microsoft implementation of the complex.h header defines these types as equivalents for the C99 standard native complex types:

Standard type                                   Microsoft type
float complex or float _Complex _Fcomplex
double complex or double _Complex _Dcomplex
long double complex or long double _Complex _Lcomplex

您可以使用 typdef 和宏来解决其中的一些问题,as demonstrated in this answer .

关于c - 如何在 Windows 上通过 clang 使用 C99 复数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57341319/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com