Thread: Structure defintion

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    8

    Structure defintion

    Hi,
    A structure is defined as follows:

    Code:
    struct value
    {
    int bit1:1;
    int bit3:4;
    int bit4:4;
    }bit={1,2,2};
    Is it assigning value 1,4,4 to bit1,bit3 and bit4,respectively?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    1,2,2 are the values assigned.
    1,4,4 are the number of bits allocated to each variable (look up bit fields).

    A signed bit-field with a width of 1 can only store 0 or -1 by the way.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-18-2010, 04:14 AM
  2. Problem Passing Structure Reference To Function
    By soj0mq3 in forum C Programming
    Replies: 9
    Last Post: 04-24-2010, 10:27 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 05:48 PM