Little bit of variable declaration syntax

This is a discussion on Little bit of variable declaration syntax within the C Programming forums, part of the General Programming Boards category; Hi, there's a little bit of syntax I can't seem to find advice on through Google. The following struct has ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    2

    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?

    Code:
    struct {
            unsigned myVariable:1;
    ...
    Thanks!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

    --
    Mats
    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
    Posts
    2
    Awesome, thanks!

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

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    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, 06: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, 03:28 PM
  3. how to compile projects ?
    By manzoor in forum C++ Programming
    Replies: 31
    Last Post: 10-15-2008, 12:52 PM
  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

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