gpt4 book ai didi

c - gcc sizeof float _Imaginary

转载 作者:行者123 更新时间:2023-12-04 10:27:30 24 4
gpt4 key购买 nike

我正在尝试获取 gcc 数据类型的字节存储大小。下面列出了我正在使用的程序。

// limits.c
// show data type storage size in bytes
#include <stdio.h>
#include <limits.h>

int main(int argc, char* args[]) {
printf(" Type Bytes\n");
printf(" ---------------------------\n");
printf(" char................... %d \n", sizeof(char));
printf(" unsigned char.......... %d \n", sizeof(unsigned char));
printf(" signed char............ %d \n\n", sizeof(signed char ));

printf(" int.................... %d \n", sizeof(int));
printf(" unsigned int........... %d \n", sizeof(unsigned int));
printf(" signed int............. %d \n\n", sizeof(signed int));

printf(" short.................. %d \n", sizeof(short ));
printf(" unsigned short......... %d \n", sizeof(unsigned short));
printf(" signed short........... %d \n\n", sizeof(signed short));

printf(" long................... %d \n", sizeof(long ));
printf(" unsigned long.......... %d \n", sizeof(unsigned long));
printf(" signed long............ %d \n\n", sizeof(signed long));

printf(" long................... %d \n", sizeof(long long));
printf(" unsigned long.......... %d \n", sizeof(unsigned long long));
printf(" signed long............ %d \n\n", sizeof(signed long long));

printf(" float _Complex......... %d \n", sizeof(float _Complex));
printf(" double _Complex........ %d \n", sizeof(double _Complex));
printf(" long double _Complex... %d \n\n", sizeof(long double _Complex));

// printf(" float _Imaginary....... %d \n", sizeof(float _Imaginary));
// printf(" double _Imaginary...... %d \n", sizeof(double _Imaginary));
// printf(" long double _Imaginary. %d \n", sizeof(long double _Imaginary));

printf(" Press any key to exit...");
getchar();
return 0;
}

除了我尝试获取_Imaginary数据类型的大小(我已将其注释掉以确保程序正常运行)之外,该代码有效。我正在使用“gcc -std=gnu99 -o %OUT% %SRC%”,这应该强制 C99 合规性。我必须做什么才能让这个 sizeof 起作用?

最佳答案

您收到语法错误,因为 gcc 未实现 _Imaginary:

来自gcc c99 status page :

GCC does not support the Annex G imaginary types, but this support is optional ...

引用自cppreference on _Imaginary_I :

A compiler that defines __STDC_IEC_559_COMPLEX__ is not required to support imaginary numbers. POSIX recommends checking if the macro _Imaginary_I is defined to identify imaginary number support. (since C99) (until C11)

Imaginary numbers are supported if __STDC_IEC_559_COMPLEX__ is defined. (since C11)

原始问题使用C99,但gcc也在C11模式下定义了__STDC_IEC_559_COMPLEX__,即使它不支持_Imaginary,这有点烦人,听起来像是一种违规的标准。

关于c - gcc sizeof float _Imaginary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53563600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com