4 ms·
long is definitely worse than int. At least you know int is never 64-bit on desktops, and it comes in handy enough for things like logarithms. long being either
by mehrdadn 6y ago
long is definitely worse than int. At least you know int is never 64-bit on desktops, and it comes in handy enough for things like logarithms. long being either 32-bit or 64-bit on the same platform depending on the compiler just feels like insanity.
- MaulingMonkey 6y agoIt's absolutely insanity. A cruel question I came up with the other day, based on it - What is the result of: std::is_signed<decltype(1L * 2U)>() ?
- folmar 6y agoWhy should it be cruel? Promotions are a part of life of an integer in C.
- MaulingMonkey 6y agoEven 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".
- mehrdadn 6y agoWow that is cruel! Somehow I just assumed int would get promoted to long regardless of their size difference. That this isn't the case almost seems like a language defect!