Q1 already answered perfectly by MrCode.
Q2: It is important that the line you quoted is inside a struct definition and that the following line is:
Code:
unsigned hw_lpm_support:1;
Alone and outside a struct definition, the line you asked about might just declare a one bit field as Cedrik said.
Inside a struct definition (which is where such syntax is most commonly used) it should allocate an entire unsigned int but allow that unsigned int to be shared with following bit fields.
So the immediately following hw_lpm_support in the linked code is another bit of the same unsigned int allocated by the declaration of sw_lpm_support.
Edit: I just wrote and tested a program I hoped would clarify the rules I described above. But either I misunderstood the rules myself or something is strange about my gcc.
Code:
#include <stdio.h>
typedef struct { unsigned x:1; unsigned y:1; char z; } a;
typedef struct { unsigned char x:1; unsigned char y:1; char z; } b;
int main(int argc, char *argv[])
{
printf("sizeof(a)=%d\n", sizeof(a));
printf("sizeof(b)=%d\n", sizeof(b));
return 0;
}
The size of
b is simple:
x and
y each use 1 bit of the same char,
z is another char, so the total is 2.
I thought
a would be 8.
x and
y each use 1 bit of the same unsigned int,
z is an additional char, forcing three more chars for alignment. But actually sizeof(a) was 4, meaning that
x forced a full unsigned int into the struct as I expected, but both
y and
z then used left over bits of that unsigned int. (I don't use this stuff in real work).