Results 1 to 4 of 4

Thread: INT_MIN and INT_MAX vs. LONG_MIN and LONG_MAX

  1. #1
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default INT_MIN and INT_MAX vs. LONG_MIN and LONG_MAX

    Since the range of QScrollBar can't exceed INT_MIN or INT_MAX, I looked up what those were equal to. According to cplusplus.com it's -32767 and 32767, but when I use qDebug() to print INT_MIN and INT_MAX, I get the values that cplusplus.com claims are LONG_MIN and LONG_MAX.

    I realize this might not be a Qt-specific question, but why is there this discrepancy?

  2. #2
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: INT_MIN and INT_MAX vs. LONG_MIN and LONG_MAX

    It's depend on arch, compiler etc.

    MingW and MSVC uses 4 bytes (32bits) for int and long (AFAIK for 32 and 64 bit compilation mode).

    You can see how it's defined in limits.h.

    i.e.: mingw limits.h

    Qt Code:
    1. /*
    2.  * Maximum and minimum values for ints.
    3.  */
    4. #define INT_MAX 2147483647
    5. #define INT_MIN (-INT_MAX-1)
    6.  
    7. #define UINT_MAX 0xffffffff
    8.  
    9. /*
    10.  * Maximum and minimum values for shorts.
    11.  */
    12. #define SHRT_MAX 32767
    13. #define SHRT_MIN (-SHRT_MAX-1)
    14.  
    15. #define USHRT_MAX 0xffff
    16.  
    17. /*
    18.  * Maximum and minimum values for longs and unsigned longs.
    19.  *
    20.  * TODO: This is not correct for Alphas, which have 64 bit longs.
    21.  */
    22. #define LONG_MAX 2147483647L
    23. #define LONG_MIN (-LONG_MAX-1)
    24.  
    25. #define ULONG_MAX 0xffffffffUL
    To copy to clipboard, switch view to plain text mode 

    On the cplusplus.com stated minimum ranges for particular data types, let's say guidelines, are from C99 specification. I don't know if C11 change this. In short those are minimum.maximum sizes for all platform's that int should have (i.e. 2 bytes, 16bis or 4 bytes 32 bits).

    One can say that all modern platform like Windows, Linux, MaCOSX use int as 32 bits (there are different types for 64bit int). According to this: http://www.viva64.com/en/a/0030/ even for 64bit CPU's. Of course it's not all true, You can see that in limits.h for Alphas.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  3. The following user says thank you to Talei for this useful post:

    wayfaerer (7th April 2012)

  4. #3
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Re: INT_MIN and INT_MAX vs. LONG_MIN and LONG_MAX

    Thanks for the info... very interesting!

  5. #4
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: INT_MIN and INT_MAX vs. LONG_MIN and LONG_MAX

    Btw. more about standard can be found here:
    http://www.open-std.org/jtc1/sc22/wg...s/papers/2005/
    and according to :
    http://www.open-std.org/jtc1/sc22/wg...2005/n1905.pdf
    c.3.9.1 page 62. paragraph 2:

    There are five signed integer types : “signed char”, “short int”, “int”, and “long int”., and “long long int”.
    In this list, each type provides at least as much storage as those preceding it in the list. Plain ints have the natural size
    suggested by the architecture of the execution environment44); the other signed integer types are provided to meet special
    needs.
    44* that is, large enough to contain any value in the range of INT_MIN and INT_MAX, as defined in the header <climits>.
    And qt has it's q-dataType- that is the same across all supported platforms. So if You use qint then that int is 32 bit everywhere where qt runs.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  6. The following user says thank you to Talei for this useful post:

    wayfaerer (8th April 2012)

Similar Threads

  1. Replies: 9
    Last Post: 2nd July 2014, 11:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.