comp.lang.c
[Top] [All Lists]

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

Subject: Re: Is cast operator unary or binary? How many operands?
From: JoseMariaSola
Date: Tue, 29 Apr 2008 09:47:18 -0700 PDT
Newsgroups: comp.lang.c

> > 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.

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy