Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: how cast works?
Date: Mon, 12 Aug 2024 10:04:17 -0700
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <86frr965bi.fsf@linuxsc.com>
References: <87ttfu94yv.fsf@nosuchdomain.example.com> <87bk228uzg.fsf@nosuchdomain.example.com> <86ttfqin3x.fsf@linuxsc.com> <86a5hih0nv.fsf@linuxsc.com> <87h6bqe4x8.fsf@nosuchdomain.example.com> <87mslhag4b.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Mon, 12 Aug 2024 19:04:18 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f42e4005105099d89c60a754521770ce"; logging-data="3563735"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XFAvvEhoM5rQAXh18ORjPsrouUCN0LG8="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:AAVkOCKby8OkRIM9L3vZmeRtcHE= sha1:+hhuz1d4DeMbCWRNpdG0hNkdu/U=
Xref: csiph.com comp.lang.c:387521
Ben Bacarisse writes:
> Keith Thompson writes:
>
>> Tim Rentsch writes:
>> [...]
>>
>>> Furthermore, there are cases where having to do a conversion from
>>> one type to the same type has semantic consequences, even though
>>> the types are the same.
>>
>> What are these cases?
>
> The case that comes to mind is where the result of a floating point
> expression is represented with more precision than the type can hold
> when stored.
Right.
> 6.3.1.8 p2:
> The values of floating operands and of the results of floating
> expressions may be represented in greater range and precision than
> that required by the type; the types are not changed thereby.[63]
>
> The footnote explains that the implicit conversion done on assignment
> will change the value even though the types may be the same:
>
> [63] The cast and assignment operators are still required to remove
> extra range and precision.
A related item is that the rule for 'return' is not the same as
assignment. When returning a value from a function, the value
of the return expression is converted to the return type of the
function, /unless/ the type of the return expression is the same
as the return type of the function, in which case no conversion
takes place (and so extra range and precision may be retained).