什么是结肠这个结构的定义呢? [英] What does the colon do in this struct definition?

查看:109
本文介绍了什么是结肠这个结构的定义呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  什么是'无符号温度:3是指

我不明白,这个结构的定义。这似乎违法给我,但显然它不是:

I don't understand this struct definition. It seems illegal to me, but apparently it isn't:

typedef struct
{
    unsigned i:1;
} my_struct;

我认为,这标志着变量无符号没有一个类型是一样的标记为 unsigned int类型。不过,我完全被结肠百思不得其解。它有什么作用?我的猜测是,它的一些初始化的,但我没有一个线索是什么意思。关闭我的头顶,我期望在C冒号的唯一地方是在三元运算符,这显然是没有的。所以,这似乎是与我不熟悉的结构。谁能解释一下结肠癌的目的是在这个结构定义是什么?究竟是什么的声明符号?我:1; 的意思是

I believe that marking the variable as unsigned without a type is the same as marking it as unsigned int. However, I'm completely baffled by the colon. What does it do? My guess is that it's some sort of initializer, but I haven't a clue what it means. Off the top of my head, the only place that I'd expect a colon in C is in the ternary operator, which this obviously isn't. So, this appears to be a construct with which I am not familiar. Can anyone explain what the purpose of the colon is in this struct definition? What exactly does the declaration unsigned i:1; mean?

推荐答案

它定义我是1位的宽度。
如果我:X是给定的,然后它定义我为x位宽

It defines i to be of 1 bit width. If i:x is given then it defines i to be x bits wide.

这篇关于什么是结肠这个结构的定义呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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