In this answer, you can find this comment:
Strictly speaking the bit representations of the two numbers before conversion being the same doesn't matter. Even with 1's complement or signed magnitude representations, the conversion of (signed) -1 to unsigned long will always result in
ULONG_MAX
. (The bit pattern will be the same after conversion of course).
I understand that you can represent -1
in other ways than Two's Compliment, that's a valid addition that should be in my answer. But, in such implementations, is it safe to rely on the conversion to ULONG_MAX
?