什么是C ++结构语法“a:b”意思 [英] What does C++ struct syntax "a : b" mean

查看:173
本文介绍了什么是C ++结构语法“a:b”意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个C ++结构,定义一个64位数据字,如..

If I have a C++ struct, defining a 64bit data word such as..

struct SMyDataWord
{
    int Name : 40;
    int Colour : 24;
};

:40 语法是什么意思。 ..这意味着前40位是为名称保留的,剩余的24位用于颜色?

What does the : 40 syntax mean... does it mean that the first 40 bits are reserved for the Name and the remaining 24 bits for the Colour?

这是它似乎被使用的方式,但是我没有碰到过。

This is how it appears to be being used, but I've not come across it before.

推荐答案

Bit C. code>是40位宽,颜色是24位宽。因此,您的结构至少有64位。在我的系统上,64位将是8字节。

Bitfields, carried over from C. Name is 40 bits wide, Colour is 24 bits wide. Your struct therefore has at least 64 bits. On my system 64 bits would be 8 bytes.

这篇关于什么是C ++结构语法“a:b”意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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