Concept of bit fields

Posted by user1369975 on Programmers See other posts from Programmers or by user1369975
Published on 2013-06-28T19:15:32Z Indexed on 2013/06/28 22:28 UTC
Read the original article Hit count: 189

Filed under:
|

Whenever I read a code like this:

  struct node
  {
          int x : 2;
          int p : 4;
   }n;

with bit fields involved, I get really confused, as to how they are represented in memory, what is sizeof(n) etc., how does it differ with normal members of structures? I tried referring K&R and http://en.wikipedia.org/wiki/Bit_field but they little to remove my confusion. What concepts of bit fields am I failing to grasp?

© Programmers or respective owner

Related posts about c

    Related posts about bitwise-operators