BitFlags unsigned int

This is a discussion on BitFlags unsigned int within the C Programming forums, part of the General Programming Boards category; I have the following bitflags Code: #define LEFT (1<<0) #define RIGHT (1<<1) #define UP (1<<2) #define DOWN (1<<3) but I ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    BitFlags unsigned int

    I have the following bitflags

    Code:
    #define LEFT  (1<<0)
    #define RIGHT (1<<1)
    #define UP    (1<<2)
    #define DOWN  (1<<3)
    but I only assign them to unsigned int's

    is it better to use

    Code:
    #define LEFT  (1U<<0)
    #define RIGHT (1U<<1)
    #define UP    (1U<<2)
    #define DOWN  (1U<<3)
    or it doesnt matter??

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Since int is guaranteed to be larger than four bits, I can't see that it matters. (int and unsigned int have to be the same size, and the conversion is transparent--i.e., it doesn't change the bit pattern unless you're not on a twos complement machine--so I don't think there's any extra work involved.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 01:05 PM
  2. Need Help Please
    By YouShallNotPass in forum C++ Programming
    Replies: 3
    Last Post: 08-22-2006, 12:22 PM
  3. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 07:45 AM
  4. Can't Find Conio.h?
    By drdroid in forum C++ Programming
    Replies: 27
    Last Post: 09-26-2002, 05:24 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM

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