为什么int16_t complex
不能编译,而在x86和x86_64机器上的int16_t
,是short int
上的typedef?以下是使用C99和C11标准对gcc 5.4和4.9进行测试的示例代码。编译器抱怨在声明说明符中有两个或多个数据类型。为什么'int16_t complex'不起作用?
代码:
#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,%+f)\n", creal(y), cimag(y));
printf("z=(%+f,%+f)\n", 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
您确定在C99模式('-std = c99')下运行时会接受'short int complex'吗?考虑提高警告水平。 – alk
@alk是的。即使有'--pedantic'和'-Wall -Werror' –