用C确切的宽度整数类型(stdint.h) [英] Exact-width integer types in C (stdint.h)

查看:349
本文介绍了用C确切的宽度整数类型(stdint.h)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想焦炭,短期和int类型为1,2和4个字节的宽度。我已经包括一个 stdint.h 头到我的消息来源。这是否保证中int8_t,int16_t和int32_t整数类型将宽度指定?什么是实现这一目标的最佳途径?

I would like char, short and int types to be 1, 2 and 4 bytes width. I have included a stdint.h header into my sources. Does this guarantee that int8_t, int16_t and int32_t integer types will be of widths specified? What is the best way to achieve this?

推荐答案

如果存在这些类型的,他们有正确的宽度,并都设有两补codeD。

If these types exist, they have the correct width and are encoded in two's complement.

编辑:你应该能够检查是否有类似的东西存在的各类

you should be able to check if the types exist with something like

#ifdef INT32_MAX
...
#endif

但(PC等)上的所有最终用户架构这些类型通常做存在。

but on all end user architectures (PC etc) these types do usually exist.

这篇关于用C确切的宽度整数类型(stdint.h)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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