变量声明后跟冒号? [英] Variable declaration followed by colon?

查看:130
本文介绍了变量声明后跟冒号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这代表什么?


unsigned int n:6;


???


Saverio

What does this represent?

unsigned int n : 6;

???

Saverio

推荐答案

sa **********@gmail.com 说:

这代表什么?


unsigned int n:6;
What does this represent?

unsigned int n : 6;



参见The C Programming Language,第2版,作者:Kernighan和Ritchie,

第149-150页。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www 。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

See "The C Programming Language", 2nd edition, by Kernighan and Ritchie,
pages 149-150.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这代表什么?
What does this represent?

unsigned int n:6;
unsigned int n : 6;



在结构或联合中,它代表一个无符号整数

位域,占用6位;

在结构或联合之外,它表示语法错误。

玩得开心。

Inside a structure or union, it represents an unsigned integral
bitfield that occupies 6 bits;
Outside a structure or union, it represents a syntax error.
Have fun.


2008年4月12日15:17,Yunzhong写道:
On 12 Apr 2008 at 15:17, Yunzhong wrote:

这代表什么?

unsigned int n:6;
What does this represent?
unsigned int n : 6;



在结构或联合中,它代表一个占空比为6位的无符号整数

位域;


Inside a structure or union, it represents an unsigned integral
bitfield that occupies 6 bits;



也许OP会想知道为什么这样的东西会有用。


几个使用位域的常见例子是设备驱动程序,

因为标志(即位)的组合通常存储在硬件中的单个

字节中;和二进制数据格式,它们经常包含在字节边界没有对齐的
字段。无论你是否意识到这一点,或者每次发送IP数据包都依赖于bitfields!

这里是'的IP头结构'是在每个数据包中使用:


struct iphdr {

unsigned int version:4;

unsigned int ihl:4;

u_int8_t tos;

u_int16_t tot_len;

u_int16_t id;

u_int16_t frag_off;

u_int8_t ttl;

u_int8_t协议;

u_int16_t check;

u_int32_t saddr;

u_int32_t daddr;

};

Perhaps the OP will wonder why such a thing could be useful.

A couple of common examples where bitfields are used are device drivers,
because combinations of flags (i.e. bits) are often stored in a single
byte in hardware; and binary data formats, which frequently contain
fields that aren''t aligned at byte boundaries. Whether you realize it or
not, you''re relying on bitfields every time you send an IP packet!
Here''s the IP header struct that''s used in every packet:

struct iphdr {
unsigned int version:4;
unsigned int ihl:4;
u_int8_t tos;
u_int16_t tot_len;
u_int16_t id;
u_int16_t frag_off;
u_int8_t ttl;
u_int8_t protocol;
u_int16_t check;
u_int32_t saddr;
u_int32_t daddr;
};


这篇关于变量声明后跟冒号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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