Deutsch   English   Français   Italiano  
<v95lb7$26koh$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups: comp.lang.c
Subject: Re: how cast works?
Date: Fri, 9 Aug 2024 13:57:59 -0400
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <v95lb7$26koh$1@dont-email.me>
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> <v94pji$m1ib$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 09 Aug 2024 19:58:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ab5add5a204e6155067e82be1eb57cd0";
	logging-data="2315025"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+znp0nqjZaW/PY027IbjhSlEuEEAuF0qw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:WSEUXiykjjPOvmzLB/OKdSgmzBQ=
Content-Language: en-US
In-Reply-To: <v94pji$m1ib$1@dont-email.me>
Bytes: 3031

On 09/08/2024 12:04, Bart wrote:
> On 09/08/2024 00:17, Keith Thompson wrote:
....
>> There is no such thing as an "implicit cast" in C.
>>
> 
> Suppose I write this code:
> 
>      x = a;                  // implicit 'conversion'
>      x = (double)a;          // explicit 'conversion'
> 
> 
> My compiler produces these two bits of AST for the RHS of both expressions:
> 
> 1 00009 r64---|---2 convert: sfloat_c i32 => r64
> 1 00009 i32---|---|---1 name: t.main.a.1
> 
> 1 00010 r64---|---2 convert: sfloat_c i32 => r64
> 1 00010 i32---|---|---1 name: t.main.a.1

Of course - an implicit conversion has exactly the same effect as a
explicit conversion, if the source and destination types are the same.
That doesn't make it correct to use the term "cast" to describe anything
other than an explicit conversion.
> 
> So whatever you call that `(double)` part of the second line, which is 
> written explicitly, exactly the same thing is done internally (ie 
> 'implicitly') to the first line. (The 09/10 are line numbers.)
> 
> Since C likes to use the term 'cast' for such conversions, ...

No, C only uses the term "cast" to describe the following:

"6.5.4	Cast operators
1 cast-expression:
unary-expression
( type-name ) cast-expression" (6.5.4p1)

A cast is a piece of syntax that is used to explicitly request that a
conversion be performed. Conversions that are explicitly requested in C
code are referred to as casts only by people who don't understand what
they're saying - the standard never refers to them as such.

> ... I don't see a 
> problem with talking about implicit and explicit versions.

There's nothing wrong with talking about implicit conversions versus
explicit conversions. Explicit conversion are also called casts.