ABI什么,如果有的话,限制[U]还会将intmax_t的大小? [英] What ABI, if any, restricts the size of [u]intmax_t?

查看:176
本文介绍了ABI什么,如果有的话,限制[U]还会将intmax_t的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与1999年版开始,ISO C标准定义了一个标准的头< stdint.h> 定义,除其他事项外,该类型定义还会将intmax_t uintmax_t型。这些候,分别为A(签字|无符号)整数能够重新presenting中的任何类型的任何值(有符号|无符号)整数类型。

Starting with the 1999 edition, the ISO C standard defines a standard header <stdint.h> which defines, among other things, the typedefs intmax_t and uintmax_t. These designate, respectively, "a (signed|unsigned) integer type capable of representing any value of any (signed|unsigned) integer type".

例如,如果是典型,最广泛和无符号整数类型得到long long int 无符号长long int类型,这两者通常是64位,那么还会将intmax_t uintmax_t型可能中定义&LT; stdint.h&GT; 如下:

For example, if, as is typical, the widest signed and unsigned integer types are long long int and unsigned long long int, both of which are typically 64 bits, then intmax_t and uintmax_t might be defined in <stdint.h> as follows:

typedef long long int intmax_t;
typedef unsigned long long int uintmax_t;

有一组$ P $有限pdefined符号和无符号整数类型,从签署无符号和纯字符高达签署无符号 得到long long int

There is a limited set of predefined signed and unsigned integer types, ranging from signed, unsigned, and plain char up to signed and unsigned long long int.

C99和C11还允许实现定义的扩展整型的,这是不同于任何标准的类型,并具有实现定义关键字的名称。

C99 and C11 also permit implementations to define extended integer types, which are distinct from any of the standard types and have names that are implementation-defined keywords.

GCC和铛,对一些但不是所有的目标,支持类型 __ int128 无符号__int128 。这些像128位的整数类型,但它们的的对待的扩展整型的,并且两种编译器的文档指出,他们不支持任何扩展整型。因为这些都不是的整数类型的作为标准定义的术语,该类型定义还会将intmax_t uintmax_t型是64位的类型,不是128位的类型。

Both gcc and clang, on some but not all targets, support types __int128 and unsigned __int128. These act like 128-bit integer types, but they are not treated as extended integer types, and the documentation for both compilers states that they do not support any extended integer types. Because these are not integer types as the Standard defines the term, the typedefs intmax_t and uintmax_t are for 64-bit types, not 128-bit types.

这一切都不违反了C标准(实现不要求有任何扩展整型,而且他们允许有任意扩展,只要不破坏任何严格符合程序)。但在我看来,它将使完美的意义 __ int128 无符号__int128 被视为扩展整数类型,和还会将intmax_t uintmax_t型为128位的类型。

None of this violates the C standard (implementations are not required to have any extended integer types, and they're permitted to have arbitrary extensions as long as they don't break any strictly conforming programs). But it seems to me that it would make perfect sense for __int128 and unsigned __int128 to be treated as extended integer types, and for intmax_t and uintmax_t to be 128-bit types.

有关的理由的的这样做是不断变化的的大小还会将intmax_t uintmax_t型将是一个ABI不兼容的变化。

The rationale for not doing this is that changing the size of intmax_t and uintmax_t would be "an ABI-incompatible change".

借助锵C ++状态页面说,脚注(5):

需要进行诸如锵一个实现,它不提供任何扩展整型未编译的变化。 __ int128 不被视为一个扩展的整数类型,因为更改还会将intmax_t 将是一个ABI不兼容的改变。

No compiler changes are required for an implementation such as Clang that does not provide any extended integer types. __int128 is not treated as an extended integer type, because changing intmax_t would be an ABI-incompatible change.

(是的,这主要是讨论的C ++,但规则是相同的对C)。

(Yes, this primarily discusses C++, but the rules are the same as for C.)

在一个 gcc的bug报告,索赔是由如下:

In a gcc bug report, the claim is made that:

的sizeof(还会将intmax_t)是由多种LP64的ABI固定的,不能改变。

sizeof(intmax_t) is fixed by various LP64 ABIs and cannot be changed

在这两种情况下,没有参考,给出了这一说法。

In both cases, no reference is given for this claim.

这是 x86_64的ABI文件名为System V应用程序二进制接口,AMD64架构处理器补充,版本草案0.99.6并没有提及还会将intmax_t uintmax_t型,甚至&LT; stdint.h&GT; 头。它指定predefined整数类型的大小和对齐(见图3.1)。

An x86_64 ABI document titled "System V Application Binary Interface, AMD64 Architecture Processor Supplement, Draft Version 0.99.6" does not mention intmax_t or uintmax_t, or even the <stdint.h> header. It does specify sizes and alignments for the predefined integer types (in Figure 3.1).

最后,我的问题:是声称的还会将intmax_t 尺寸和 uintmax_t型由ABI限制?如果是这样,ABI强加这样的要求? (而且,顺便说一句,为什么?)

Finally, my question: Is the claim that the sizes of intmax_t and uintmax_t restricted by an ABI? If so, what ABI imposes such a requirement? (And, incidentally, why?)

(在我看来,这样的要求,如果存在的话,是不明智的。它违背C标准的定义扩展整型许可的目的,和的本意还会将intmax_t uintmax_t型,这使得它更难以在支持他们,而回落至其他系统上的窄型系统有效地使用128位的整数类型。)

(In my opinion, such a requirement, if it exists, is unwise. It defeats the purpose of the C standard's permission to define extended integer types, and the intended meaning of intmax_t and uintmax_t. It makes it much more difficult to use 128-bit integer types effectively on systems that support them, while falling back to narrower types on other systems.)

参考文献:

  • N1256, a draft of the C99 standard
  • N1570, a draft of the C11 standard
  • System V AMD64 ABI

推荐答案

随着上校三十二笔记,编译器单方面做出这种改变会破坏编译单元之间的调用,通过 uintmax_t型参数或返回 uintmax_t型值。即使SysV的ABI没有定义这些类型的传递方式,作为实用性保持其定义的问题是符合平台ABI的一部分。

As Colonel Thirty Two notes, a compiler unilaterally making this change would break calls between compilation units that pass uintmax_t parameters or return uintmax_t values. Even though the SysV ABI doesn't define how these types are passed, as a matter of practicality maintaining their definitions is part of conforming to the platform ABI.

即使没有这个问题ABI,编译器仍然不能单方面做出这种改变,因为这需要每一个目标平台的C标准库匹配的变化。具体地讲,它至少需要更新的的printf scanf函数函数族, imaxabs imaxdiv strtoimax strtoumax 及其变种。

Even if it weren't for this ABI issue, a compiler still couldn't unilaterally make this change, because it would require matching changes to every targeted platform's C standard library. Specifically, it would at least require updates to the printf and scanf function family, imaxabs, imaxdiv, and strtoimax and strtoumax and their variants.

这篇关于ABI什么,如果有的话,限制[U]还会将intmax_t的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆