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++ 中的固定宽度整数


基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01