ULLONG_MAX Question

This is a discussion on ULLONG_MAX Question within the C++ Programming forums, part of the General Programming Boards category; I'm working on a project where the code uses unsigned long long int to tag what a certain variable represents ...

  1. #1
    DSM
    DSM is offline
    Registered User
    Join Date
    Mar 2010
    Posts
    3

    ULLONG_MAX Question

    I'm working on a project where the code uses unsigned long long int to tag what a certain variable represents (1 represents apples, 2 oranges, 4 bananas, 8 pineapples...). Now, we are limited to 64 different variable types because ULLONG_MAX is specified to be 2^64 in limit.h. What if I want to represent 200 different variable types? Is there a way to change ULLONG_MAX to be equal to 2^200? Can this be done inside the code so limit.h does not have to be changed on each machine we use? Is this even possible if we're only using a 64 bit OS (openSuse)?

    My advisor claims that he has used our 64 bit unsigned long long int strategy on 32 bit machines, so theoretically we should be able to do more than 64 bit operations on 64 bit machines. Also, the way the code is set up would require outrageous changes to no longer use this unsigned long long int, so (at least for now) they are determined not to change how this works.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    Quote Originally Posted by DSM
    Now, we are limited to 64 different variable types because ULLONG_MAX is specified to be 2^64 in limit.h. What if I want to represent 200 different variable types?
    You may be able to #include <bitset> and use a std::bitset<200>.

    By the way, at the moment, long long and unsigned long long are not part of standard C++, but may be available as a compiler extension.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    DSM
    DSM is offline
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    Quote Originally Posted by laserlight View Post
    You may be able to #include <bitset> and use a std::bitset<200>.
    So does this mean there is no way to maintain the unsigned long long int format? Everything will have to be converted to bitsets?

    Thanks for the reply

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    write your own class that is wrapper for the bitset
    overload all operators that are used in current code so they could be applied the same way to the variable of new type without rewriting the existing code (except the places where the variable is constructed)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    Luckily, std::bitset already overloads various operators and might even be an almost drop in replacement for what you already have.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    DSM
    DSM is offline
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    Thanks for the help everyone!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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