这在 c int a:16; 中是什么意思? [英] what does this mean in c int a:16;?

查看:40
本文介绍了这在 c int a:16; 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
'unsigned temp:3' 是什么意思?

请问这个符号是什么意思

please what does this notation mean

int a:16;

我发现它是这样的代码并且它确实可以编译.

I found it is code like this and it does compile.

结构名称{输入:16;}

struct name { int a:16; }

推荐答案

这是一个位域.

这个特定的位域没有多大意义,因为您只能使用 16 位类型,并且您正在浪费一些空间,因为位域被填充到 int 的大小.

This particular bitfield doesn't make much sense as you just could use a 16-bit type and you're wasting some space as the bitfield is padded to the size of int.

通常,您将它用于包含位大小元素的结构:

Usually, you are using it for structures that contain elements of bit size:

struct {
    unsigned nibble1 : 4;
    unsigned nibble2 : 4;
}

这篇关于这在 c int a:16; 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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