我需要在 gcc 编译的 C 程序中声明一个 80 位大小的变量(我需要它来将数据传递给工作在 fpu 上的 asm 过程,它被这个用 C 编写的程序调用)
我的架构是 AMD x64
我尝试了 long double
、__float80
,但对于它们,sizeof
返回 12 而不是 10
。
那么如何声明这样的变量呢?
最佳答案
该大小包括用于对齐的填充,但它仍然是一个 80 位值。 manual说:
-m96bit-long-double
-m128bit-long-double
These switches control the size of long double type. The x86-32 application binary interface specifies the size to be 96 bits, so -m96bit-long-double is the default in 32-bit mode.
Modern architectures (Pentium and newer) prefer long double to be aligned to an 8- or 16-byte boundary. In arrays or structures conforming to the ABI, this is not possible. So specifying -m128bit-long-double aligns long double to a 16-byte boundary by padding the long double with an additional 32-bit zero.
In the x86-64 compiler, -m128bit-long-double is the default choice as its ABI specifies that long double is aligned on 16-byte boundary.
Notice that neither of these options enable any extra precision over the x87 standard of 80 bits for a long double.
Warning: if you override the default value for your target ABI, this changes the size of structures and arrays containing long double variables, as well as modifying the function calling convention for functions taking long double. Hence they are not binary-compatible with code compiled without that switch.
-mlong-double-64
-mlong-double-80
-mlong-double-128
These switches control the size of long double type. A size of 64 bits makes the long double type equivalent to the double type. This is the default for 32-bit Bionic C library. A size of 128 bits makes the long double type equivalent to the __float128 type. This is the default for 64-bit Bionic C library.
Warning: if you override the default value for your target ABI, this changes the size of structures and arrays containing long double variables, as well as modifying the function calling convention for functions taking long double. Hence they are not binary-compatible with code compiled without that switch.
关于c - 如何定义 80 位大小的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29730626/