Thread: BitFlags unsigned int

  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,336
    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, 12:05 PM
  2. Need Help Please
    By YouShallNotPass in forum C++ Programming
    Replies: 3
    Last Post: 08-22-2006, 11:22 AM
  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, 04: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