UINT32 x : 1 ?

This is a discussion on UINT32 x : 1 ? within the C Programming forums, part of the General Programming Boards category; Hi all, I saw this somewhere. UINT32 x : 1; May I know what is the purpose of declaring the ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    4

    Question UINT32 x : 1 ?

    Hi all,
    I saw this somewhere.
    UINT32 x : 1;

    May I know what is the purpose of declaring the data type to 32 bits, but only 1 bit is in use? Is this related to hardware logic?

    Thanks for the help.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, UINT32 is a "unsigned long" (or "unsigned int" - both may well be 32 bits, unsigned long may also be 64 bits), which tells the compiler that the bit is to fit inside an unsigned long word. It's still only represented with one bit, and there's no REAL difference between that and "unsigned short" or "unsigned char". The size of the struct will be at least 32 bits [assuming of course that UINT32 is correctly defined and no other rules in the system will extend the structure (e.g. the compiler has a rule that no structure can be smaller than 64 bits)].

    --
    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
    Jun 2008
    Posts
    4
    what i would like to ask is why UINT32 is used instead of UINT8 etc?
    what is the usage of this definition?
    UINT32 x : 1;
    ':1' means only one bit is used, how about other 31 bits?
    if i have 2 definition below,
    UINT32 x : 1;
    UINT32 y : 1;
    there will be how many UINT32 is in use?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mottoshiritai View Post
    what i would like to ask is why UINT32 is used instead of UINT8 etc?
    what is the usage of this definition?
    UINT32 x : 1;
    ':1' means only one bit is used, how about other 31 bits?
    if i have 2 definition below,
    UINT32 x : 1;
    UINT32 y : 1;
    there will be how many UINT32 is in use?
    In your second case, there's one UINT32 [although this is also completely guaranteed - see below], which has two bits defined (most likely adjascent bits, but it's not guaranteed by any of the C/C++ standards - the internal structure of bit fields is entirely up to the compiler vendor).

    Not sure if this clarifies things much, but it describes in different words what I've just said:
    http://publib.boulder.ibm.com/infoce...c03defbitf.htm

    --
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. MD5 hashing problems =(
    By Uncle Rico in forum C Programming
    Replies: 4
    Last Post: 02-28-2005, 09:31 AM
  3. MD5 Algorithm
    By Inquirer in forum C Programming
    Replies: 2
    Last Post: 12-28-2003, 10:55 PM
  4. bit shifting
    By Nor in forum C++ Programming
    Replies: 9
    Last Post: 08-08-2003, 11:55 AM
  5. libtiff: TIFFWriteRGBAImage()?
    By dug in forum Game Programming
    Replies: 1
    Last Post: 07-09-2003, 09:01 AM

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