C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为什么’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是类型@L_696_6@的一部分,就像long一样.你不能这样做:

typedef double dbl;
typedef long dbl ldbl;

即,当使用typedef为double时,尝试为long double定义ldbl的typedef!同样,在定义复杂类型时不能使用typedef(例如int16_t is),而是使用short int _Complex.

(当然这也适用于复杂,因为它只是一个扩展到_Complex的宏).

大佬总结

以上是大佬教程为你收集整理的为什么’int16_t complex’不起作用?全部内容,希望文章能够帮你解决为什么’int16_t complex’不起作用?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。