DWORD or bool*

This is a discussion on DWORD or bool* within the C++ Programming forums, part of the General Programming Boards category; I want to store 26 bits, one for each letter in the alphabet that I want to be true or ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    11

    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
    Posts
    9
    If datasize and speed don't matter, i should use the array version. DWORD bit..........ing is probably faster.

  3. #3
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    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
    Posts
    9,590
    Use a dword.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,651
    Code:
    #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;
    }//IsBitSet
    gg

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

    "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, 03:48 PM
  2. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 01: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, 09:17 AM

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