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



On Apr 29, 1:47 pm, JoseMariaSola <JoseMariaS...@xxxxxxxxx> wrote:
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.

The last line of my last post shoudl be:
... the middle token is anything an identifier may be and more.

Here is part of the grammar:

unary-expression:
postfix-expression
++ unary-expression
-- unary-expression
unary-operator cast-expression
sizeof unary-expression
sizeof ( type-name )

unary-operator: one of
& * + - ˜ !

cast-expression:
unary-expression
( type-name ) cast-expression


Why sizeof, (type-name), ++ and -- aren't unary-operators?

Thanks.
.



Relevant Pages

  • Re: Precedence of sizeof
    ... unary-operator cast expression ... sizeof unary-expression ... sizeof (type-name) ...
    (comp.lang.c)
  • Re: question on fgets
    ... sizeof unary-expression ... and they go round a type-name. ... It is true that a cast-expression is: ...
    (comp.lang.c)
  • Re: question on fgets
    ... I.e. in the form that needs they are part of the unary-expression ... and they go round a type-name. ... It is true that a cast-expression is: ... sizeof unary-expression ...
    (comp.lang.c)
  • Re: Precedence of sizeof
    ... unary-operator cast expression ... sizeof unary-expression ... sizeof (type-name) ...
    (comp.lang.c)
  • Re: Is cast operator unary or binary? How many operands?
    ... unary-operator cast-expression ... sizeof unary-expression ... sizeof (type-name) ...
    (comp.lang.c)