1

Possible Duplicate:
Bitfield manipulation in C

I saw some c codes, typedef a struct, like

typedef struct
{
    unsigned a:1;
    unsigned b:1;
    unsigned c:1;
    unsigned rest:13;

} Interface_type;

what dose unsigned a:1; mean?

Community
  • 1
  • 1
How Chen
  • 1,340
  • 2
  • 17
  • 37

2 Answers2

4
unsigned a:1

Defines a bit field that only occupies 1 bit.

See here: http://en.wikipedia.org/wiki/Bit_field

sashang
  • 11,704
  • 6
  • 44
  • 58
  • very thanks...I never use bit field...if bit fied better than bit mask? I think it will have problem when porting maybe? – How Chen Sep 12 '12 at 07:21
  • I'm not sure about porting it - I guess the things that could go wrong would depend on the compiler for that target platform. – sashang Sep 12 '12 at 07:29
  • 1
    bitfields are horrible for porting. The standard does specify the layout so it is compiler specific. Really should stay away from them and uses mask for portability. – James Sep 12 '12 at 07:38
  • @James, yes, I agree with you – How Chen Sep 12 '12 at 07:50
1

Signed variables, such as signed integers will allow you to represent numbers both in the positive and negative ranges.

Unsigned variables, such as unsigned integers, will only allow you to represent numbers in the positive

Elendas
  • 733
  • 3
  • 8
  • 22