Possible Duplicate:
What does ‘unsigned temp:3’ means
I’m learning some kernel code, and came along the following line (in linux 2.4, sched.h, struct mm_struct):
unsigned dumpable:1;
What does this mean?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a bitfield member. Your code means
dumpableoccupies exactly 1 bit in the structure.Bitfields are used when you want to pack members in bit-level. This can greatly reduce the size of memory used when there are a lot of flags in the structure. For example, if we define a struct having 4 members with known numeric constraint
then the struct could be declared as
then the bits of Foo may be arranged like
instead of
in which many bits are wasted because of the range of values
so you can save space by packing many members together.
Note that the C standard doesn’t specify how the bitfields are arranged or packed within an “addressable storage unit”. Also, bitfields are slower compared with direct member access.