C++ U32 类型头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7218220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 16:37:24  来源:igfitidea点击:

C++ U32 type header

c++c

提问by Tiago Costa

I want to use U32type but I can't find the header where it is defined. Does anyone know?

我想使用U32类型,但找不到定义它的标题。有人知道吗?

回答by Seth Carnegie

There is no standard type called U32, but if you #include <cstdint>(stdint.hfor C) you can use std::uint32_t1, a 32 bit unsigned integer, which is (I assume) what you want.

没有称为 的标准类型U32,但是如果您#include <cstdint>stdint.h对于 C)您可以使用std::uint32_t1,一个 32 位无符号整数,这是(我假设)您想要的。

Here is a list of types in the cstdintheader:

这是标题中的类型列表cstdint

namespace std {
    int8_t
    int16_t
    int32_t
    int64_t
    int_fast8_t
    int_fast16_t
    int_fast32_t
    int_fast64_t
    int_least8_t
    int_least16_t
    int_least32_t
    int_least64_t
    intmax_t
    intintptr_t
    uint8_t
    uint16_t
    uint32_t
    uint64_t
    uint_fast8_t
    uint_fast16_t
    uint_fast32_t
    uint_fast64_t
    uint_least8_t
    uint_least16_t
    uint_least32_t
    uint_least64_t
    uintmax_t
    uintintptr_t
}

1Thanks Martinho Fernandes for pointing out that these types are in the namespace std.

1感谢 Martinho Fernandes 指出这些类型在命名空间中std

回答by Kornel Kisielewicz

While cstdint might be a solution, it's not universal -- MSVC versions before 2010 didn't ship with that one. If writing for multiple platforms you'll need to supply the standard types yourself if MSVC < 2010 is detected. Or use the boost oneif you use boost.

虽然 cstdint 可能是一种解决方案,但它并不通用——2010 年之前的 MSVC 版本没有附带那个。如果为多个平台编写,如果检测到 MSVC < 2010,您需要自己提供标准类型。或者使用升压一个,如果你使用的推动作用。

回答by user46748

U32 is an idiomatic shortcut for an unsigned int. Its common definition is:

U32 是 unsigned int 的惯用快捷方式。它的通用定义是:

typedef unsigned int U32;

But the main reason for its use is to be able to control the actual definition manually. Hope this helps.

但使用它的主要原因是能够手动控制实际定义。希望这可以帮助。