Jump to content
  • Advertisement
Sign in to follow this  
Arch_DOA

Relationship of size of variable, operation system and maximum and var can hold

This topic is 4817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a forumla or something that tells me the maximum a variable can hold on a certain operating system. My programming in C book doesn't really explain it that well. Like say i have a short int which is 2 bytes. And im using Windows 32. What would be the maxiumum the variable can hold. Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Well, yeah, there is a formula. And that would be 2bytes*8 for unsigned integral numbers or 2bytes*8-1 for signed.. Though the formula doesn't fit for a bool, even though it's 1 byte in size.

I think mgarriss was referring to the STL numeric_limits template class for C++. Which you could use thusly:

#include <limits>
cout << "int max: " << std::numeric_limits<int>::max() << endl;
cout << "short max: " << std::numeric_limits<short>::max() << endl;


You can find a full listing of the numeric_limits class methods
  • yea thanks for the help.. I was just looking for that forumla. Although I cant get the signed formula to work. Also is 8 just a random number or does that have a significance..

    Share this post


    Link to post
    Share on other sites
    Guest Anonymous Poster
    8 is the number of bits in a byte... usually. A more accurate formula is:

    2^(bits)

    Share this post


    Link to post
    Share on other sites
    the AP was me: when I say 'usually' I mean that it's not required to be 8 bits a byte. A byte is the size of a char in c/c++ by the standard and the char just has to be a minimum size and that's it. So a byte could be 20 bits, or 10, or 9.... that's why using the standard limits is a better idea because it's not safe to assume.

    Share this post


    Link to post
    Share on other sites
    Sign in to follow this  

    • Advertisement
    ×

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    We are the game development community.

    Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

    Sign me up!