Jump to content

declaring an integer in a C program

- - - - -

  • Please log in to reply
2 replies to this topic

#1
onus

onus

    Programmer

  • Members
  • PipPipPipPip
  • 115 posts
On this link I came across
LXR / The Linux Cross Reference
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?

#2
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
This syntax is normally used to declare a member in structure bitwise. In C language, we can declare a member and set how many bits it would take: we can declare such kind of members, and when next member is defined as normal such as 'int j' - then bytes are rounded to multiple of 8 bits.

For example,


struct B

{

    unsigned a: 4;    //  4 bits


    unsigned b: 1;    // +1 bit, same group, (4+1 is rounded to 8 bits as next data member is normal variable definition)


    unsigned char c;  // +8 bits


    unsigned d: 7;    // + 7 bits


};

//                    sizeof(B) = 3 (4+1 rounded to 8 + 8 + 7 = 23, rounded to 24)


I hope this helps!

Munir

#3
onus

onus

    Programmer

  • Members
  • PipPipPipPip
  • 115 posts
Yes thanks this helps.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users