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?
Asked
Active
Viewed 8,294 times
6

Armen Tsirunyan
- 130,161
- 59
- 324
- 434

reality displays
- 731
- 3
- 9
- 18
-
3It's probably some preprocessor magic happening. – OmnipotentEntity Nov 23 '10 at 07:00
-
17Why the hell does the above comment have 2 upvotes? – Armen Tsirunyan Nov 23 '10 at 07:09
-
1@OmnipotentEntity and the two upvoters: it's a bitfield. – JeremyP Nov 23 '10 at 09:51
-
1When did magic start working in C? – Nov 23 '10 at 15:49
5 Answers
9
I think you have come across a bit-field :)

Armen Tsirunyan
- 130,161
- 59
- 324
- 434
-
ha ha :) ok by reading rest of the replies I am now able to understand what is the above thing. – reality displays Nov 23 '10 at 10:08
3
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.

Ignacio Vazquez-Abrams
- 776,304
- 153
- 1,341
- 1,358
3
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.
0
In struct
s, 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.

Jonas Kölker
- 7,680
- 3
- 44
- 51
-
1where you get the number 31 from? This is misleading. You may use as many as the width of `int`, which is at least 32. You should be a bit cautious about the sign bit, but since here the field is declared `unsigned int` it can hold at least 32 bit without pain. – Jens Gustedt Nov 23 '10 at 09:34
-
1