Sujet : Re: how cast works?
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 09. Aug 2024, 21:59:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v96000$3fvsp$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
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 don't see a
problem with talking about implicit and explicit versions.
There's nothing wrong with talking about implicit conversions versus
explicit conversions.
Of course! Because those terms happen to be used in a couple of places in the standard. Usage of any terms not appearing in the standard is apparently outlawed in this newsgroup.
Explicit conversion are also called casts.
"6.5.4p3
Conversions that involve pointers, other than where permitted by the constraints of 6.5.16.1, shall be specified by means of an explicit cast."
Here it uses the term 'explicit cast'. Why is that; isn't the term 'cast' unambiguous without needing to say 'explicit'?
Also, what is exactly is the difference between 'explicit conversion' and 'explicit cast'?
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.
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, but even if it did, surely people ought to be allowed to use alternate terms for an informal discussion? This is a not a committee meeting.
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:"
Look also at H.2.4p4 (also p5):
"C’s conversions (casts) from floating-point to floating-point can meet LIA−1 requirements if an implementation uses round-to-nearest (IEC 60559 default)."
Here it clearly indicates that 'conversions' (presumably both implicit and explicit) are also known as 'casts'.
This seems to imply (no pun) that 'implicit casts' are a thing; the opportunity to use that term just never came up.
I don't wish to be rude to you or KT but .....