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.
精彩评论