Fixed-width integers in C++(C++ 中的固定宽度整数)
问题描述
有时我需要使用固定宽度的整数来与 PLC 等外部设备进行通信.我还使用它们来定义位掩码并执行图像数据的位操作.AFAIK C99 标准定义了固定宽度的整数,如 int16_t.但是,我使用的编译器 VC++ 2008 不支持 C99 并且 AFAIK Microsoft 不打算支持它.
Occasionally I need to use fixed-width integers for communication with external devices like PLCs. I also use them to define bitmasks and perform bit manipulation of image data. AFAIK the C99 standard defines fixed-width integers like int16_t. However the compiler I use, VC++ 2008 doesn't support C99 and AFAIK Microsoft is not planning to support it.
我的问题是在 C++ 中使用固定宽度整数的最佳实践是什么?
My question is what is the best practice for using fixed-width integers in C++?
我知道 VC++ 定义了像 __int16 这样的非标准固定宽度整数,但我对使用非标准类型犹豫不决.下一个 C++ 标准会定义固定宽度的整数吗?
I know that VC++ defines non-standard fixed-width integers like __int16, but I am hesitant to use a non-standard type. Will the next C++ standard define fixed-width integers?
推荐答案
Boost 具有适用于所有 C99 类型及更多类型的 typedef:"Boost 整数库"
Boost has the typedefs for all of the C99 types and more: "Boost integer library"
这篇关于C++ 中的固定宽度整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 中的固定宽度整数
基础教程推荐
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
