문제

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

도움이 되었습니까?

해결책

I think you have come across a bit-field :)

다른 팁

It's part of a struct, which means that it indicates that the field should only use a certain number of bits instead of an entire byte or more.

This is bit field declaration in an array. The number post ":" denotes 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 are passing binary blobs between interfaces compiled with different compilers it may not work.

This indicates that only one bit of this will be used.

In structs, one can have integer variables that occupy any number of bits between 1 and 31. is_added is such a one-bit variable. One-bit variables are also known as flags.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top