c/c++单冒号

发布于 2024-11-26 06:59:41 字数 418 浏览 2 评论 0原文

可能的重复:
“unsigned temp:3”是什么意思

我是 c/c++ 的新手我在 linux 和 win32 上运行了这段代码

typedef struct tMessageAction
{
    unsigned char ActionId : 4;
    unsigned short ID : 10;
}tMessageAction;

,那么单冒号对这个变量做了什么? 他们是否指定将使用多少位? 这与某种类型的结构对齐属性有关吗?

Possible Duplicate:
What does 'unsigned temp:3' means

I'm a newbie to c/c++ and I have this code running on linux and win32

typedef struct tMessageAction
{
    unsigned char ActionId : 4;
    unsigned short ID : 10;
}tMessageAction;

so what are the single colons doing to this variables?
are they specifying how many bits are going to be used?
is this related to some type of structure alignment attribute?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静谧 2024-12-03 06:59:41

冒号定义位字段。它们不会改变对齐规则。

The colons are defining a bitfield. They do not change the alignment rules.

云裳 2024-12-03 06:59:41

以下是关于 C 位字段的信息。

Here's about the C Bit fields.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文