C++ 在c++代码中,下面的关键字是什么意思?SIGSELECT, U32, U16, U8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6412042/
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 20:05:35  来源:igfitidea点击:

In c++ code, what do the following keywords mean? SIGSELECT, U32, U16, U8

c++structtypedef

提问by unwind

I have a question about keyword usage in a c++ struct.

我有一个关于 c++ 结构中关键字使用的问题。

I have seen a struct defined like this:

我见过这样定义的结构:

typedef struct {
    SIGSELECT signo;
    U32 id;
    U32 re;
    U16 id1;
    U8 id2;
}First;

Please help me understand these keywords: SIGSELECT,U32,U16,U8

请帮我理解这些关键字:SIGSELECT,U32,U16,U8

回答by unwind

What they "mean" is a quite deep question, and also depends on the environment you are in.

他们的“意思”是一个相当深奥的问题,也取决于你所处的环境。

Those are type names, but not standard C++ types so they're not universally known.

这些是类型名称,但不是标准的 C++ 类型,因此它们并不广为人知。

A guess would be that the Uxxtypes are "unsigned integers", of the specified bit widths. So U32would be a 32-bit unsigned integer, what is known as uint32_tin C99 but has not yet been standardized in C++.

猜测是这些Uxx类型是指定位宽的“无符号整数”。所以U32将是一个 32 位无符号整数,这uint32_t在 C99 中被称为但尚未在 C++ 中标准化。

SIGSELECTis a bit harder, but the member is named "signo" which implies that this is a signal number. If the code is for a POSIX-like environment, it's quite likely that SIGSELECTis simply an alias for the default integer type, int. See this pagefor instance.

SIGSELECT有点难,但该成员名为“ signo”,这意味着这是一个信号编号。如果代码用于类似 POSIX 的环境,则很可能SIGSELECT只是默认整数类型的别名,int. 例如,请参阅此页面

Some header does either

一些标题要么

#define SIGSELECT int

or

或者

typedef int SIGSELECT;

in order to introduce this new name (and similiarly for the other types mentioned).

为了引入这个新名称(对于提到的其他类型也是如此)。

To figure out if these are preprocessor symbols or actual typedef:ed type aliases, run the code through the preprocessor and read its output. If the wording changes (i.e. SIGSELECTturns into intor some other type) they are preprocessor symbols, otherwise they are typedef:s.

要确定这些是预处理器符号还是实际的typedef:ed 类型别名,请通过预处理器运行代码并读取其输出。如果措辞改变(即SIGSELECT变成int或其他类型),它们是预处理器符号,否则它们是typedef:s。

回答by tony gil

as @AJG85 mentioned in a comment on this thread, you can port the datatypes by including the standard library CSTDINT

正如对此线程的评论中提到的@AJG85,您可以通过包含标准库 CSTDINT 来移植数据类型

#include <cstdint>

this excellent article by Alex Allaindescribes the library and these datatypes in more detail.

Alex Allin 的这篇优秀文章更详细地描述了库和这些数据类型。