Thread: Little bit of variable declaration syntax

  1. #1
    Registered User
    Join Date
    Nov 2008

    Little bit of variable declaration syntax

    Hi, there's a little bit of syntax I can't seem to find advice on through Google. The following struct has members with a colon and then a number afterward, is this the value to which the variable is to be first set?

    struct {
            unsigned myVariable:1;

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    No, it's the number of bits you want the variable to have. In this instance, the value is 1 bit, which means that the only possible values are 0 and 1.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Awesome, thanks!

  4. #4
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Such code is used to force padding of the structure to fit within certain boundaries, ideal for embedded system architectures.

  5. #5
    Join Date
    Oct 2007
    Inside my computer
    Not only. It's ideal to assign the bits within the structs.
    It's only a shame that the use of it is usually non-portable due to alignment.
    But it's useful is you know data is compromised of n number of bits of n sections with data.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PlaySound
    By cangel in forum C++ Programming
    Replies: 16
    Last Post: 10-08-2009, 05:29 PM
  2. spliting 16bit variable into LSB and MSB 8 bit variables
    By Spiral Prophet in forum C Programming
    Replies: 2
    Last Post: 10-30-2008, 02:28 PM
  3. how to compile projects ?
    By manzoor in forum C++ Programming
    Replies: 31
    Last Post: 10-15-2008, 11:52 AM
  4. variable into 1 bit??
    By theeld in forum C Programming
    Replies: 3
    Last Post: 10-29-2006, 04:57 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM