Thread: DWORD or bool*

  1. #1
    Registered User
    Join Date
    Dec 2003

    DWORD or bool*

    I want to store 26 bits, one for each letter in the alphabet that I want to be true or false. I would store this in a boolean-array like this:

    bool alphabet[26];

    but I noticed that some functions (like GetLogicalDrives()) use a DWORD to store the 26 bits in. I'd say that for stuff like this a boolean-array would be way easier because you don't have to use any bit-comparison. So.. why is a DWORD used instead of a boolean-array, and should I use a DWORD for situations like this too?

  2. #2
    Registered User
    Join Date
    Oct 2003
    If datasize and speed don't matter, i should use the array version. DWORD is probably faster.

  3. #3
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    I always do it the DWORD way, why use 26 bools when one int can do it?
    May be hard to [understand|work with] at the beginning, but once you get used to it, you'll like it.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Use a dword.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    #define IsBitSet(val, bit) (((val) & (1 << (bit))) ? true : false)
    // or for type safety
    template<typename integer_t>
    inline bool IsBitSet(const integer_t &val, const size_t &bit)
        return (val & (1 << bit)) ? true : false;

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Use a std::bitset.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 04:48 PM
  2. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 02:54 PM
  3. Getting position from game..
    By brietje698 in forum C++ Programming
    Replies: 1
    Last Post: 10-26-2007, 12:15 PM
  4. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  5. storage size of regs is unkown
    By Vertex34 in forum C Programming
    Replies: 5
    Last Post: 11-04-2003, 10:17 AM