Re:A Special Kind of Hell: intmax_t in C and C++
by folmar on Sunday December 06, 2020 @02:14PM
(#25325818)
Why should it be cruel? Promotions are a part of life of an integer in C.
[ Parent
| on HN ]
Re:A Special Kind of Hell: intmax_t in C and C++
by MaulingMonkey on Sunday December 06, 2020 @07:35PM
(#25328107)
Even programmers who are roughly aware of integral promotion rules may not have connected all the dots to realize the answer is implementation dependent.
If sizeof(long) == sizeof(unsigned int), 1L * 2U results in an unsigned int, meaning the result is "false".
If sizeof(long) > sizeof(unsigned int), 1L * 2U result in a signed long, meaning the result is "true".