How to declare unsigned int in a C program

I came across this link http://lxr.linux.no/#linux+v2.6.36/include/linux/pci.h#L299 integer declaration unsigned int is_added:1; I made C programs and declared integers in them, but in the above I see usage : What is this syntax?

+6
c bit-fields
source share
5 answers

I think you are faced with a bit field :)

+9
source share

This is part of a struct , which means that it indicates that the field should use only a certain number of bits instead of an integer byte or more.

+3
source share

This is a bit field declaration in an array. The number post ":" indicates the number of bits to allocate to this particular field of the structure.

Although you need to be careful with bit fields, as their binary representation is not portable. That is, you pass binary blobs between interfaces compiled with different compilers, this may not work.

+3
source share

This means that only one bit will be used.

+1
source share

In struct s, there may be integer variables that occupy any number of bits between 1 and 31. is_added is such a one-bit variable. Single-bit variables are also known as flags.

0
source share

All Articles