开发者

C special syntax (adding ':' ) while defining a struct [duplicate]

开发者 https://www.devze.com 2023-03-15 18:08 出处:网络
This question already has an answer here: Closed 11 years ago. Possible Duplicate: What does the : do in a struct declaration after a member
This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

What does the : do in a struct declaration after a member

I would like to ask why the : character was added i开发者_JAVA百科n this struct:

typedef union A
{
struct 
    {
        ubyte B:4;
         }
} struct_a;

Thanks in advance;


The :4 is putting a 4-bit limit on the variable. See Section 6.9 of Kernighan & Ritchie.


It's called a bit field. In this case it is saying the B is 4 bits in size.


It declares a bit field with 4 bits.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号