Sujet : Re: What is your opinion about unsigned int u = -2 ?
De : vir.campestris (at) *nospam* invalid.invalid (Vir Campestris)
Groupes : comp.lang.cDate : 11. Aug 2024, 21:08:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v9b5od$2rta7$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 11/08/2024 20:33, Tim Rentsch wrote:
Ick. That choice is exactly backwards IMO. Converting -1 to
an unsigned type always sets all the bits. Converting -1u to
an unsigned type can easily do the wrong thing, depending
on the target type.
"Converting -1 to an unsigned type always sets all the bits"
In any normal twos complement architecture that's the case. But there are a few oddballs out there where -1 is +1, except that the dedicated sign bit is set.
Andy