Is there some meaningful statistical data to justify keeping signed integer arithmetic overflow undefined?

I don’t know about studies and statistics, but yes, there are definitely optimizations taking this into account that compilers actually do. And yes, they are very important (tldr loop vectorization for example). Besides the compiler optimizations, there is another aspect to be taken into account. With UB you get C/C++ signed integers to behave arithmetically … Read more

How do I deal with “signed/unsigned mismatch” warnings (C4018)?

It’s all in your things.size() type. It isn’t int, but size_t (it exists in C++, not in C) which equals to some “usual” unsigned type, i.e. unsigned int for x86_32. Operator “less” (<) cannot be applied to two operands of different sign. There’s just no such opcodes, and standard doesn’t specify, whether compiler can make … Read more

Can a pointer (address) ever be negative?

No, addresses aren’t always positive – on x86_64, pointers are sign-extended and the address space is clustered symmetrically around 0 (though it is usual for the “negative” addresses to be kernel addresses). However the point is mostly moot, since C only defines the meaning of < and > pointer comparisons between pointers that are to … Read more

Unsigned hexadecimal constant in C?

The number itself is always interpreted as a non-negative number. Hexadecimal constants don’t have a sign or any inherent way to express a negative number. The type of the constant is the first one of these which can represent their value: int unsigned int long int unsigned long int long long int unsigned long long … Read more