Re: Is cast operator unary or binary? How many operands?



I'd say one operator, the cast operator, and two operands: typename
and expression.

But everywhere I read, cast is categorized as an unary operator. Why
is that? Is it just a syntax cotegory?

(typename)(expression) has one operator `(typename)' and one operand
`(expression)'.
The reason the type is enclosed in parentheses (as a design decision)
is probably to avoid ambiguity, consider this:

int i = 1; /* define and initialize i to 1 */
{
int i; /* cast i to int, a statement with no effect, or define i in
block scope? */

}

Thanks, Vipps.

According to your answeer, the operator '(typename)' is very
particular, because it not a single token but three AND the middle
token is anything an identifier may be.

JM.
.



Relevant Pages

  • Re: New large text benchmark
    ... int main ... a good idea to insert parentheses to clarify possible ... to 'int', possible loss of data ... use parentheses to clarify precedence ...
    (comp.compression)
  • Re: K&R2 1.6 Arrays, exercise 1-13 (vertical histogram)
    ... | int main ... I thought you always initialised variables on declaration, ... This, of course, could have been done by initialising on declaration ... (If the latter reason is true, learning it would have done no good here, because Reason 1 would still have applied.) ...
    (comp.lang.c)
  • Re: New large text benchmark
    ... int main ... Same probably with the operator precedence, but also here it would be a good idea to insert parentheses to clarify possible misinterpretations. ... to 'int', possible loss of data ... use parentheses to clarify precedence ...
    (comp.compression)
  • Re: size_t overflow
    ... means all computations involving unsigned char promoted to int, ... The Standard does not define "operand." ... So we see that promotion has reduced the number of kinds ...
    (comp.std.c)
  • Re: Semantics of unary minus
    ... unsigned int b; ... "The result of the unary - operator is the negative of its operand. ... The integer promotions are performed on the operand, and the result has the promoted type." ... and the resulting representation ...
    (comp.lang.c)