Equivalence <limits> and <climits>

  • Is it always guaranteed:

    std::numeric_limits<int>::max() == INT_MAX
    

    What does the C ++ standard say about this? I could not find any reference in the standard that would explicitly indicate this, but I continue to read that they should be equivalent.

  • What about C99 types that do not comply with the C ++ 98 standard for compilers that implement both C99 (at least long longpart) and C ++ 98? I am not sure if there is a guarantee that this is always true:

    std::numeric_limits<unsigned long long>::max() == ULLONG_MAX
    

    Is that a reasonable guess?

+3
source share
4 answers

My copy of the C ++ 2003 standard says templates numeric_limits<>::max()and min()will return values:

CHAR_MIN, SHRT_MIN, FLT_MIN, DBL_MIN, ..

CHAR_MAX, SHRT_MAX, FLT_MAX, DBL_MAX, ..

, . ISO/IEC 3: "[] ". .

+4

: std::numeric_limits<int>::max() == INT_MAX.

unsigned long long , / . ...

unsigned long long, , , .

, .

+2

, ++, ++ . , , .

+1

Although, as far as I know, it is not part of the standard, this is certainly a reasonable assumption, especially if you have compilers from the same package or provider. For example, g ++ 4.3 just uses #defined values ​​from <limits>in <climits>.

0
source

Source: https://habr.com/ru/post/1704876/


All Articles