C++ 中的固定宽度整数 [英] Fixed-width integers in C++

查看:23
本文介绍了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++ 中的固定宽度整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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