Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: does a double cast to unsigned makes sense in any circumstance? Date: Sun, 16 Jan 2022 13:30:58 -0800 Organization: None to speak of Lines: 19 Message-ID: <87y23fxt9p.fsf@nosuchdomain.example.com> References: <86czl8kaew.fsf@levado.to> <8635lotrby.fsf@levado.to> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="edefa9a574b14021f379bca5fa220c53"; logging-data="26742"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199ITurHKR2h0tdi0Z6ukwz" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:u3YFL1oL/qpbxOsPrYgN5J7MTsI= sha1:qS0u0VYIVtK974tvAwzCVi5f7u8= Xref: csiph.com comp.lang.c:164431 James Kuyper writes: [...] > "... the value is converted by repeatedly adding ... one more than the > maximum value that can be represented in the new type until the value is > in the range of the new type." (6.3.1.3p2). > > It's the other direction that's dangerous: conversion of an integer > value to a signed integer type that is not representable in that type > has undefined behavior. No, converting an out-of-range integer value to a signed integer type yields an implementation-defined result or raises an implementation-defined signal. (C99 added the option of raising a signal; in my opinion that was a bad idea.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */