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



In article <13115f63-fd53-4436-879d-4dab6f0fcd84@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
JoseMariaSola <JoseMariaSola@xxxxxxxxx> wrote:

But in the case of cast the (only) operand is the expression the left,
not the type-name.

I see, you want to consider, say, (int) as an operator with a single
operand, rather than (int)x containing an operator with two operands,
"int" and "x".

This would imply an infinite number of operators, which is not
out of the question but doesn't seem to offer any advantage.

Talking with you both I notice that every operator requires
expressions as operands, and type-name is not an expression. Am I
right?

The two traditional uses of "( type-name )" - in casts and sizeof -
and the new use in C99 - in compound literals - are indeed
exceptional. I previously suggested that we could factor out

type-expression:
( type-name )

which would make sizeof in particular more regular:

unary-expression:
...
sizeof unary-expression
sizeof type-expression

-- Richard
--
:wq
.



Relevant Pages

  • Re: question on fgets
    ... The parenthesis to sizeof is not required except for types. ... sizeof unary-expression ... and they go round a type-name. ...
    (comp.lang.c)
  • Re: sizeof a returns 4
    ... sizeof 'c' == sizeof ... A pair of parentheses is required when type names applied to sizeof ... sizeof (type-name) ... for similar reasons in both cases (to avoid ambiguity), ...
    (comp.lang.c)
  • Re: malloc and functions
    ... and it is odd even for an operator: ... int main ... their operands. ... I think the main reason for the confusion is that sizeof is the only ...
    (comp.lang.c)
  • Re: Is cast operator a binary or a unary operator?
    ... the type-name and the expression on the ... There's only one operand: ... any parenthesized type-name. ... and both versions of sizeof as a binary operator. ...
    (comp.std.c)
  • Re: Three programs with sizeof
    ... > Why doesn't the compiler see 'int foo'? ... It is correct with the error since the syntax for using sizeof with a ... type-name is to have brackets around the type-name. ...
    (comp.lang.cpp)