Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Vir Campestris Newsgroups: comp.lang.c Subject: Re: What is your opinion about unsigned int u = -2 ? Date: Sun, 11 Aug 2024 21:08:45 +0100 Organization: A noiseless patient Spider Lines: 13 Message-ID: References: <87mslxe4wj.fsf@bsb.me.uk> <86y152n9c8.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 11 Aug 2024 22:08:45 +0200 (CEST) Injection-Info: dont-email.me; posting-host="6c077d9e1b97e54f47b6445ce1758c56"; logging-data="3011911"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1810rVF96xDqI6lBQl1fB1HJqwcXqs/ZSE=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:oRZUXLugR8Ivb/bjCxCnwXIG9gs= Content-Language: en-GB In-Reply-To: <86y152n9c8.fsf@linuxsc.com> Bytes: 1562 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