Re: how cast works?

Liste des GroupesRevenir à cl c  
Sujet : Re: how cast works?
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.c
Date : 10. Aug 2024, 01:32:39
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v968un$7kfh$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Mozilla Thunderbird
On 09/08/2024 22:47, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 09/08/2024 18:57, James Kuyper wrote:
On 09/08/2024 12:04, Bart wrote:
>
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.
>
Are you sure? What else would they be known as?
 I believe James made a small error here, either omitting a "not" or
accidentally writing "explicitly" rather than "implicitly".
 With that correction, I presume what James wrote is clear enough.
I ask you not to pretend that you still don't understand it.
I guessed it was some sort of mistake. That's why I politely asked if he was sure.
 > I ask you not to pretend that you still don't understand it.
I might also ask you not to pretend you don't know what is meant by 'implicit cast'. Or worse, pretending that other people might be confused.
I'm sure most of those won't have gone anywhere near the standard, so they won't be aware that in the 700 pages of N1570.PDF, 'explicit cast' occurs all of once, while 'implicit cast' occurs one time less often, which appears to be the sole reason for have a go at anyone who commits the sin of using that expression.

[...]
Here it uses the term 'explicit cast'. Why is that; isn't the term
'cast' unambiguous without needing to say 'explicit'?
 It's redundant.
OK. Does that mean we're allowed to use redundant terms too?

Also, what is exactly is the difference between 'explicit conversion'
and 'explicit cast'?
 The both mean the same thing in C, but "explicit cast" is redundant.
 
Why can't there also be a similar correlation between 'implicit
conversion' and 'implicit cast'? The only reason I can see is that out
of these four terms, only 3 of them happen to appear in the standard.
 Because a cast is an explicit operator.
It's something that is done in the code to alter the evaluation of some expression. An 'explicit cast', which has to be requested in the source code, necessarily has some syntax associated with it.
An 'implicit cast' (by which I mean, for your benefit as it puzzles nobody else, implicit type conversion), obviously /doesn't/ have any relevant syntax! If it had, then it would be explicit...

I don't see that as a compelling reason why that term should be
considered absolutely wrong; 'implicit cast' just never came up.
>
It's not as though the standard provides an official glossary,
 In fact it does.  Some terms are defined in section 3, and others are
defined elsewhere in the standard (definitions are denoted by italics).
I don't see a definition for the term "cast", but it's clearly described
in N3220 6.5.4 "Cast operators".
 Array indexing is defined in terms of pointer arithmetic.  The
evaluation of `a[i]` involves an implicit addition operation.  It does
not involve an implicit "+" symbol.
You've snipped my quote from H.2.4p5 where it says:
   ... conversions (casts) ...
Here they are also 'mixing up' operations and syntax.
Here's the signature of a function from my C compiler which deals with conversions:
   func docast(unit p, int t, hard=1)unit =
(A 'unit' is an AST mode; 't' is a type code.) 'hard' is 1 for an explicit conversion, and 0 for an implicit one.
(Explicit or 'hard' casts enable some conversions that would be otherwise be invalid. And in that last sentence, I used both 'cast' and 'conversion' just to avoid using the same term in quick succession. I'm sure many of the word choices in the standard are for similar reasons.)

You're allowed to write whatever nonsense you like, and the rest of us
are allowed to tell you that you're wrong.
And some of us are allowed to think or say that you're being hopelessly pedantic.

 Explain why using the word "cast" incorrectly is better than using it
correctly.  Explain why you can't just refer to explicit and implicit
conversions.  Do you have a motivation other than being annoying?
'Cast' is shorter, and more directly is associated with conversions to do with types.
In my compiler for example, '*conv*' is used in many different contexts (eg. case conversion). '*cast*' is only used in two functions, both to do with C type conversions.
But I also use both terms just to mix it up.

I remember people here getting castigated for using the term 'type
cast'. And yet, in H.2.4p1:
>
"The LIA−1 type conversions are the following type casts:"
 That wording is no longer there in more recent editions.  Annex H refers
to LIA-1 (Language Independent Arithmetic), ISO/IEC 10967–1; perhaps
that standard use the term "type casts".
My point is that even the professionals who write such documents get it 'wrong', according to you.

Date Sujet#  Auteur
7 Aug 24 * how cast works?122Thiago Adams
7 Aug 24 +* Re: how cast works?7Thiago Adams
7 Aug 24 i+- Re: how cast works?1Keith Thompson
12 Aug 24 i`* Re: how cast works?5Tim Rentsch
12 Aug 24 i `* Re: how cast works?4Vir Campestris
12 Aug 24 i  `* Challenge/exercise problem - signum() function3Tim Rentsch
12 Aug 24 i   `* Re: Challenge/exercise problem - signum() function2Lew Pitcher
12 Aug 24 i    `- Re: Challenge/exercise problem - signum() function1Tim Rentsch
7 Aug 24 +* Re: how cast works?107Dan Purgert
7 Aug 24 i+- Re: how cast works?1Keith Thompson
8 Aug 24 i+- Re: how cast works?1Lawrence D'Oliveiro
8 Aug 24 i+* Re: how cast works?101Thiago Adams
8 Aug 24 ii+* Re: how cast works?25Bart
8 Aug 24 iii`* Re: how cast works?24Michael S
8 Aug 24 iii +- Re: how cast works?1Thiago Adams
8 Aug 24 iii `* Re: how cast works?22Bart
8 Aug 24 iii  +* Re: how cast works?5Thiago Adams
8 Aug 24 iii  i+- Re: how cast works?1Thiago Adams
8 Aug 24 iii  i+* Re: how cast works?2Bart
8 Aug 24 iii  ii`- Re: how cast works?1Thiago Adams
8 Aug 24 iii  i`- Re: how cast works?1Keith Thompson
8 Aug 24 iii  `* Re: how cast works?16David Brown
8 Aug 24 iii   `* Re: how cast works?15Bart
9 Aug 24 iii    +* Re: how cast works?13David Brown
9 Aug 24 iii    i+* Re: how cast works?9Keith Thompson
9 Aug 24 iii    ii+* Re: how cast works?3Lawrence D'Oliveiro
9 Aug 24 iii    iii+- Re: how cast works?1Keith Thompson
9 Aug 24 iii    iii`- Re: how cast works?1James Kuyper
9 Aug 24 iii    ii`* Re: how cast works?5David Brown
9 Aug 24 iii    ii `* Re: how cast works?4Keith Thompson
12 Aug 24 iii    ii  `* Re: how cast works?3Tim Rentsch
12 Aug 24 iii    ii   `* Re: how cast works?2Keith Thompson
3 Sep 24 iii    ii    `- Re: how cast works?1Tim Rentsch
9 Aug 24 iii    i`* Re: how cast works?3Bart
9 Aug 24 iii    i `* Re: how cast works?2David Brown
10 Aug 24 iii    i  `- Re: how cast works?1Bart
9 Aug 24 iii    `- Re: how cast works?1Lawrence D'Oliveiro
8 Aug 24 ii`* Re: how cast works?75Keith Thompson
8 Aug 24 ii `* Re: how cast works?74Thiago Adams
8 Aug 24 ii  +* Re: how cast works?72Bart
9 Aug 24 ii  i+* Re: how cast works?47Keith Thompson
9 Aug 24 ii  ii+* Re: how cast works?38Bart
9 Aug 24 ii  iii+* Re: how cast works?2David Brown
12 Aug 24 ii  iiii`- Re: how cast works?1Bart
9 Aug 24 ii  iii+* Re: how cast works?29James Kuyper
9 Aug 24 ii  iiii+* Re: how cast works?14Bart
9 Aug 24 ii  iiiii+* Re: how cast works?3Keith Thompson
10 Aug 24 ii  iiiiii`* Re: how cast works?2Bart
10 Aug 24 ii  iiiiii `- Re: how cast works?1Keith Thompson
10 Aug 24 ii  iiiii`* Re: how cast works?10James Kuyper
13 Aug 24 ii  iiiii +- Re: how cast works?1David Brown
13 Aug 24 ii  iiiii +- Re: how cast works?1Bart
13 Aug 24 ii  iiiii `* Re: how cast works?7James Kuyper
13 Aug 24 ii  iiiii  `* Re: how cast works?6Bart
13 Aug 24 ii  iiiii   `* Re: how cast works?5Keith Thompson
13 Aug 24 ii  iiiii    `* Re: how cast works?4Bart
14 Aug 24 ii  iiiii     `* Re: how cast works?3Tim Rentsch
14 Aug 24 ii  iiiii      `* Re: how cast works?2Bart
18 Aug 24 ii  iiiii       `- Re: how cast works?1Tim Rentsch
9 Aug 24 ii  iiii+* Re: how cast works?2Keith Thompson
10 Aug 24 ii  iiiii`- Re: how cast works?1James Kuyper
9 Aug 24 ii  iiii`* Re: how cast works?12Kaz Kylheku
9 Aug 24 ii  iiii +* Re: how cast works?9Keith Thompson
10 Aug 24 ii  iiii i`* Re: how cast works?8Kaz Kylheku
10 Aug 24 ii  iiii i +* Re: how cast works?6Keith Thompson
10 Aug 24 ii  iiii i i+* Re: how cast works?3Kaz Kylheku
10 Aug 24 ii  iiii i ii+- Re: how cast works?1Keith Thompson
10 Aug 24 ii  iiii i ii`- Re: how cast works?1James Kuyper
10 Aug 24 ii  iiii i i`* Re: how cast works?2Bart
13 Aug 24 ii  iiii i i `- Re: how cast works?1David Brown
12 Aug 24 ii  iiii i `- Re: how cast works?1Tim Rentsch
10 Aug 24 ii  iiii +- Re: how cast works?1James Kuyper
12 Aug 24 ii  iiii `- Re: how cast works?1Tim Rentsch
9 Aug 24 ii  iii+* Re: how cast works?4Keith Thompson
9 Aug 24 ii  iiii`* Re: how cast works?3Bart
9 Aug 24 ii  iiii `* Re: how cast works?2Keith Thompson
9 Aug 24 ii  iiii  `- Re: how cast works?1Bart
12 Aug 24 ii  iii`* Re: how cast works?2Tim Rentsch
12 Aug 24 ii  iii `- Re: how cast works?1Bart
12 Aug 24 ii  ii`* Re: how cast works?8Tim Rentsch
12 Aug 24 ii  ii `* Re: how cast works?7Bart
12 Aug 24 ii  ii  +- Re: how cast works?1Keith Thompson
12 Aug 24 ii  ii  `* Re: how cast works?5Tim Rentsch
12 Aug 24 ii  ii   `* Re: how cast works?4Keith Thompson
12 Aug 24 ii  ii    `* Re: how cast works?3Ben Bacarisse
12 Aug 24 ii  ii     `* Re: how cast works?2Tim Rentsch
12 Aug 24 ii  ii      `- Re: how cast works?1Keith Thompson
9 Aug 24 ii  i`* Re: how cast works?24Thiago Adams
9 Aug 24 ii  i +* Re: how cast works?2Bart
9 Aug 24 ii  i i`- Re: how cast works?1Keith Thompson
9 Aug 24 ii  i +* Re: how cast works?19David Brown
9 Aug 24 ii  i i`* Re: how cast works?18Thiago Adams
9 Aug 24 ii  i i +* Re: how cast works?3Thiago Adams
9 Aug 24 ii  i i i+- Re: how cast works?1David Brown
9 Aug 24 ii  i i i`- Re: how cast works?1Keith Thompson
9 Aug 24 ii  i i +* Re: how cast works?11David Brown
10 Aug 24 ii  i i i`* Re: how cast works?10Bart
10 Aug 24 ii  i i i `* Re: how cast works?9Thiago Adams
10 Aug 24 ii  i i i  `* Re: how cast works?8Bart
11 Aug 24 ii  i i i   `* Re: how cast works?7Thiago Adams
11 Aug 24 ii  i i i    `* Re: how cast works?6Keith Thompson
9 Aug 24 ii  i i `* Re: how cast works?3Keith Thompson
9 Aug 24 ii  i `* Re: how cast works?2Keith Thompson
9 Aug 24 ii  `- Re: how cast works?1David Brown
8 Aug 24 i`* Re: how cast works?3Stefan Ram
7 Aug 24 +* Re: how cast works?6Keith Thompson
8 Aug 24 `- Re: how cast works?1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal