gpt4 book ai didi

c - C 中的精确宽度整数类型 (stdint.h)

转载 作者:太空狗 更新时间:2023-10-29 15:49:31 30 4
gpt4 key购买 nike

我希望 char、short 和 int 类型的宽度为 1、2 和 4 字节。我在源代码中包含了一个 stdint.h header 。这是否保证 int8_t、int16_t 和 int32_t 整数类型具有指定的宽度?实现这一目标的最佳方法是什么?

最佳答案

如果存在这些类型,则它们具有正确的宽度并以二进制补码编码。

编辑:您应该能够检查类型是否存在,例如

#ifdef INT32_MAX
...
#endif

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

关于c - C 中的精确宽度整数类型 (stdint.h),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4902901/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com