我遇到了一种我以前从未见过的语法。
typedef struct SomeStruct
{
unsigned char ip_version :4;
unsigned char ip_tos;
unsigned char ip_frag_offset :5;
unsigned char ip_more_fragment :1;
unsigned char ip_dont_fragment :1;
unsigned char ip_reserved_zero :1;
unsigned char ip_frag_offset1;
unsigned char ip_ttl;
} SomeHeader;
colon #;
是什么?这与使用赋值运算符相同吗?为什么要使用结肠,是否有优势或原因允许?
答案 0 :(得分:1)
这些是位字段:
应该注意的是,您可以通过在Google上搜索“c struct syntax”来找到它。对我来说,第一个结果是维基百科,它有一个bit field section