Thread: Basic doubt in C structure

  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,708
    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, 11:55 PM

Tags for this Thread