| Deutsch English Français Italiano |
|
<86a5hih0nv.fsf@linuxsc.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch <tr.17687@z991.linuxsc.com> Newsgroups: comp.lang.c Subject: Re: how cast works? Date: Sun, 11 Aug 2024 20:37:08 -0700 Organization: A noiseless patient Spider Lines: 37 Message-ID: <86a5hih0nv.fsf@linuxsc.com> References: <v8vlo9$2oc1v$1@dont-email.me> <slrnvb7kis.28a.dan@djph.net> <v929ah$3u7l7$1@dont-email.me> <87ttfu94yv.fsf@nosuchdomain.example.com> <v93a3t$6q7v$1@dont-email.me> <v93e2q$8put$1@dont-email.me> <87bk228uzg.fsf@nosuchdomain.example.com> <86ttfqin3x.fsf@linuxsc.com> <v9bmqu$2v3e1$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 12 Aug 2024 05:37:09 +0200 (CEST) Injection-Info: dont-email.me; posting-host="f42e4005105099d89c60a754521770ce"; logging-data="3282385"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18M38ZIRYWTFSGyxfBo17g2BQdHf+4VvNs=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:hpBgJ9JAWnUnCsZ6dttsswAn6+Q= sha1:DYsEMNpcgWcoy1DDvFiiQs8qDlE= Bytes: 2330 Bart <bc@freeuk.com> writes: > On 12/08/2024 01:46, Tim Rentsch wrote: > >> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: >> >>> Bart <bc@freeuk.com> writes: >>> [...] >>> >>>> Take: >>>> >>>> int a; double x; >>>> >>>> x = (double)a; >>>> >>>> The cast is implicit here but I've written it out to make it clear. >>> >>> [...] >>> >>> The *conversion* could be done implicitly, but you've used a cast (i.e., >>> an explicit conversion) to make it clear. >> >> The statement assigning to x performs two conversions: an explicit >> one caused by the cast, and an implicit one caused by the assignment >> operation. > > The 'x' term is the other side of the cast from the 'a' term. > > So after '(double)a' has been evaluated, both sides of '=' have the > type 'double', so no further conversion is needed. The C standard requires that a conversion take place as part of the assignment, even when the types are the same. 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.