为什么c说_Imaginary_I未声明? [英] Why does clang say _Imaginary_I is not declared?

查看:119
本文介绍了为什么c说_Imaginary_I未声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行

clang test.c -o test

在此文件上

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

int main()
{
    _Complex double z = 1.0 + _Imaginary_I * 2.0;
    return 0;
}

由于编译失败

error: use of undeclared identifier '_Imaginary_I'.

根据在线发布,定义了 _Imaginary_I

推荐答案

虚数和 _Imaginary_I 是可选功能在C标准中。

Imaginary numbers, and _Imaginary_I, are optional features in the C Standard.

从C11开始,复数也是可选功能,但实现通常支持。 I _Complex_I 应该可以代替。

Complex numbers are also an optional feature as of C11, but are commonly supported by implementations. I and _Complex_I should work instead.

根据标准,您应该能够在编译时通过检查以下宏的值来测试一致性:

According to the standard, you should be able to test for conformance at compile-time by checking the values of the following macros:


  • __ STDC_IEC_559_COMPLEX __ :值 1 表示存在复杂和虚构的类型并符合IEC 60559。

  • __ STDC_NO_COMPLEX __ :值 1 表示既不存在复杂类型也不存在虚类型。

  • __STDC_IEC_559_COMPLEX__: value 1 means that complex and imaginary types exist and comply with IEC 60559.
  • __STDC_NO_COMPLEX__: value 1 means that neither complex nor imaginary types exist.

但是实际上这是不可靠的,例如 gcc定义了不支持该功能的宏

However in practice this is not reliable, e.g. gcc defines the macro without supporting the feature.

这篇关于为什么c说_Imaginary_I未声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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