GCC固定大小的整数 [英] GCC Fixed Size Integers

查看:152
本文介绍了GCC固定大小的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MSVC ++编译器,可以使用 __ INT8 __ INT16 __ INT32 和类似的具有特定大小的整数。这是非常有用这就需要像自定义文件格式,硬件控制数据结构等。

On the MSVC++ compiler, one can use the __int8, __int16, __int32 and similar types for integers with specific sizes. This is extremely useful for applications which need to work with low-level data structures like custom file formats, hardware control data structures and the like.

有没有类似的等价我可以GCC编译器?

Is there a similar equivalent I can use on the GCC compiler?

推荐答案

ISO标准C,从C99的标准,增加了标准头< stdint.h> 定义这些:

ISO standard C, starting with the C99 standard, adds the standard header <stdint.h> that defines these:

uint8_t  - unsigned 8 bit
int8_t   - signed 8 bit
uint16_t - unsigned 16 bit
int16_t  - signed 16 bit
uint32_t - unsigned 32 bit
int32_t  - signed 32 bit
uint64_t - unsigned 64 bit
int64_t  - signed 64 bit

我使用这些类型的所有的时间。

I use these types all the time.

如果实现支持predefined类型与合适的尺寸和特性(其中大部分做的)。

These types are defined only if the implementation supports predefined types with the appropriate sizes and characteristics (which most do).

&LT; stdint.h&GT; 也定义类型与形式的名称(U)int_leastN_t (类型拥有的至少的指定的宽度)和(U)int_fastN_t (下称最快的类型至少有指定的宽度);这些类型是强制性的。

<stdint.h> also defines types with names of the form (u)int_leastN_t (types that have at least the specified width) and (u)int_fastN_t (the "fastest" types that have at least the specified width); these types are mandatory.

如果您使用的是旧的实现不支持&LT; stdint.h&GT; ,你可以滚你自己;一种实现方式是道格格温的Q8

If you're using an old implementation that doesn't support <stdint.h>, you can roll your own; one implementation is Doug Gwyn's "q8".

这篇关于GCC固定大小的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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