对于标准的内置类型,固定宽度整数类型是否保证为typedef? [英] Are the fixed width integer types guaranteed to be typedefs for the standard built in types?

查看:74
本文介绍了对于标准的内置类型,固定宽度整数类型是否保证为typedef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于shortunsigned long等内置类型之一,<cstdint>中的类型(例如int16_tuint_fast64_tint_least8_t)是否保证为typedef?

或者是否允许实现使用非常规内置类型来实现固定宽度类型?

解决方案

这些由C标准指定(并由C ++标准通过引用合并),这要求每个符号必须为带符号整数类型的typedef 无符号整数类型(视具体情况而定).

有符号整数类型又由核心语言定义为由标准有符号整数类型(即signed charshort intintlong intlong long int)以及任何由实现定义的扩展带符号整数类型.

类似地,核心语言将无符号整数类型定义为由标准无符号整数类型(即unsigned charunsigned short intunsigned intunsigned long intunsigned long long int)以及与扩展的有符号整数类型相对应的任何实现定义的扩展的无符号整数类型.

简而言之,每个typedef可以是通常的内置类型之一,也可以是实现定义的扩展整数类型.大多数编译器不支持扩展整数类型,因此在那些编译器上,它们必须是内置类型.

Are the types from <cstdint> (like e.g. int16_t, uint_fast64_t, int_least8_t) guaranteed to be typedefs for one of the built in types like short, unsigned long etc.?

Or is an implementation allowed to use types that are non of the usual built in ones to implement the fixed width types?

解决方案

These are specified by the C standard (and incorporated by reference by the C++ standard), which requires each to be a typedef for a signed integer type or unsigned integer type, as the case may be.

signed integer type is in turn defined by the core language to consist of the standard signed integer types (which are signed char, short int, int, long int and long long int) and any implementation-defined extended signed integer types.

Similarly, unsigned integer type is defined by the core language to consist of the standard unsigned integer types (which are unsigned char, unsigned short int, unsigned int, unsigned long int and unsigned long long int) and any implementation-defined extended unsigned integer types corresponding to the extended signed integer types.

In short, each of those typedefs may be one of the usual built-in types or an implementation-defined extended integer type. Most compilers do not support extended integer types, so on those compilers they must be built-in types.

这篇关于对于标准的内置类型,固定宽度整数类型是否保证为typedef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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