问题
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__
: value1
means that complex and imaginary types exist and comply with IEC 60559.__STDC_NO_COMPLEX__
: value1
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