Thread: ULLONG_MAX Question

  1. #1
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Luckily, std::bitset already overloads various operators and might even be an almost drop in replacement for what you already have.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    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, 01:47 AM