开发者

int variable:3;

In C I saw this code:

struct stud{
int b:3;
};

This was compiling in gcc. What do variables b and 3 开发者_JAVA技巧represent? Also, please explain the use of :.

Are there anymore signs like this?


It means that b uses 3 bits of the int. The term is "bit field".

Usually this is combined with other variables using other bits of the same or other ints.

The idea is to either pack values harder to save space, or more common to match the data from some hardware device.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜