Sujet : Re: how cast works?
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 13. Aug 2024, 14:01:13
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v9flep$3sphj$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : Mozilla Thunderbird
On 13/08/2024 12:51, James Kuyper wrote:
On 8/9/24 18:29, James Kuyper wrote:
Bart <bc@freeuk.com> writes:
...
Why can't there also be a similar correlation between 'implicit
conversion' and 'implicit cast'?
>
The C standard defines "implicit conversion" and "explicit conversion"
in 6.3p1, and the definition it provides for "explicit conversion" is
"those [conversions] that result from a cast operation". it provides a
grammar production for a cast expression, and none for a implicit cast
expression.
Note, in particular, that if there were such a thing as an implicit
cast, then, as the name implies, an implicit cast would qualify as a
cast. Since, according to the above definition, all conversions that
result from casts would qualify as "explicit conversions", that would
include conversions that result from implicit casts. In other words, all
conversions would be explicit conversions. In addition, per 6.3p1, the
conversions described in 6.3 would also be implicit conversions, which
is just plain ridiculous.
If that were the case then the use of 'cast' would be more likely to be qualified.
I get that the standard mainly intends 'cast' to mean that bit of syntax, '(T)X', by which you can force a particular conversion.
But '(T)X' can also be described as a conversion, or an explicit conversion, or a coercion (this more where an automatic implicit conversion does not exist), as well as a cast.
Then I think it's perfectly acceptable to use all these terms interchangeably when there is no confusion. In that case, using 'implicit cast' to mean the same as explicit or automatic conversion shouldn't present any problems.
Other than to C Standard purists.
Of course, if it is necessary to be much more precise and specific /for a reason/, then you'd need to take more care.