Deutsch English Français Italiano |
<v9cp7f$38p3u$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!feeds.phibee-telecom.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Vir Campestris <vir.campestris@invalid.invalid> Newsgroups: comp.lang.c Subject: Re: What is your opinion about unsigned int u = -2 ? Date: Mon, 12 Aug 2024 11:47:11 +0100 Organization: A noiseless patient Spider Lines: 29 Message-ID: <v9cp7f$38p3u$1@dont-email.me> References: <v8dfo9$1k7cg$1@dont-email.me> <87mslxe4wj.fsf@bsb.me.uk> <86y152n9c8.fsf@linuxsc.com> <v9b5od$2rta7$1@dont-email.me> <v9b8c0$2sac4$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 12 Aug 2024 12:47:12 +0200 (CEST) Injection-Info: dont-email.me; posting-host="9e8135423bf13137e8c00c2554caafde"; logging-data="3433598"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cu+22xs5c5GAlFJ1skHQVat1R1nxBljg=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:QFl7obwMb/GmHEnrDk/h40EX950= Content-Language: en-GB In-Reply-To: <v9b8c0$2sac4$1@dont-email.me> Bytes: 2329 On 11/08/2024 21:53, James Kuyper wrote: > On 8/11/24 16:08, Vir Campestris wrote: > ... >> "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. > > There may be hardware where that is true, but a conforming > implementation of C targeting that hardware cannot use the hardware's > result. It must fix up the result produced by the hardware to match the > result required by the C standard. > On 11/08/2024 21:45, Richard Damon wrote: > > But, when that -1 value is converted to an unsigned type, that VALUE > will be adjusted modulo the appropriate power of two. > > signed to unsigned conversion works on VALUE, not bit pattern, so is > invariant with the representation of the negative values. > > Yes, in a union with a signed and unsigned, the type punning will let > you see the representation of the types, but assignment works on values. Ah, thank you both. It's academic interest only of course! Andy