Basic doubt in C structure

This is a discussion on Basic doubt in C structure within the Linux Programming forums, part of the Platform Specific Boards category; Hi all, I was navigating inside linux kernel code and inside that one i have seen few structures which are ...

  1. #1
    VIM addict
    Join Date
    May 2009
    Location
    Chennai, India
    Posts
    43

    Basic doubt in C structure

    Hi all,

    I was navigating inside linux kernel code and inside that one i have seen few structures which are very strange (for me). The structure is of the following form

    Code:
    struct dummy {
         int a:1;
         unsigned long b:5;
    };
    In the above structure does anyone explain me what is the number after the : will do.

    Thanks in advance
    -BalaC-

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,702
    It's called a bitfield.

  3. #3
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    a is a bitfield (like an int or char, but with one bit). b too, but with five bits. "a = 2" will probably give 0, since the upper bits are chopped off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  2. structure ...solution plz????
    By hegdeshashi in forum C Programming
    Replies: 4
    Last Post: 07-24-2006, 09:57 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Doubt -- Structures
    By bmsar in forum C Programming
    Replies: 0
    Last Post: 12-25-2002, 10:55 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21