本文介绍了什么是int8_t如果机器有> 8位/字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阅读,并说

那么,< cstdint> 类型是什么意思?



我应该使用 int8_t char 为什么?

intX_t (即确切的宽度整数类型)typedefs作为可选



如果你想要一个字节数组,你应该使用 char sizeof char (和 signed char unsigned char )定义为总是1个字节。


I was reading the C++ FAQ and it says

So what does that mean for the <cstdint> types?

Side question - if I want an array of bytes should I use int8_t or char and why?

解决方案

C++ (and C as well) defines intX_t (i.e. the exact width integer types) typedefs as optional. So, it just won't be there if there is no addressable unit that's exactly 8-bit wide.

If you want an array of bytes, you should use char, as sizeof char (and signed char and unsigned char) is well-defined to always be 1 byte.

这篇关于什么是int8_t如果机器有&gt; 8位/字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:01