为什么’int16_t complex’不起作用?
为什么int16_t complex在x86和x86_64机器上的int16_t时不能编译,在short int上是typedef?以下是使用
gcc 5.4和4.9测试的示例代码,其中包含C99和C11标准.编译器抱怨在声明说明符中有两个或更多数据类型.
码: #include <complex.h> #include <stdint.h> #include <stdio.h> int main() { float complex x = I + I / 3 * I / 2; short int complex y = I + I / 3 * I / 2; int16_t complex z = I + I / 3 * I / 2; /* Why ? */ printf("x=(%+f,%+f)n",creal(x),cimag(x)); printf("y=(%+f,creal(y),cimag(y)); printf("z=(%+f,creal(z),cimag(z)); /* Why ? */ return 0; } 错误: In file included from ./complex.c:1:0: ./complex.c: In function ‘main’: ./complex.c:9:13: error: two or more data types in declaration specifiers int16_t complex z = I + I / 3 * I / 2; /* Why ? */ 编译器命令行: gcc-5 --std=c99 ./complex.c -o ./complex gcc-4.9 --std=c99 ./complex.c -o ./complex 解决方法
首先,复杂的整数类型是GCC扩展. C标准说(
C11 6.2.5p11):
_Complex是类型名称的一部分,就像long一样.你不能这样做: typedef double dbl; typedef long dbl ldbl; 即,当使用typedef为double时,尝试为long double定义ldbl的typedef!同样,在定义复杂类型时不能使用typedef(例如int16_t is),而是使用short int _Complex. (当然这也适用于复杂,因为它只是一个扩展到_Complex的宏). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |