Why does clang say _Imaginary_I is not declared?

邮差的信 提交于 2019-12-10 22:24:21

问题


Running

clang test.c -o test

On this file

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

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

fails to compile because of

error: use of undeclared identifier '_Imaginary_I'.

According to onlinepubs, _Imaginary_I is defined. What happened?


回答1:


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

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__: 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.

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



来源:https://stackoverflow.com/questions/45002381/why-does-clang-say-imaginary-i-is-not-declared

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!