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



On Apr 29, 3:45 pm, JoseMariaSola <JoseMariaS...@xxxxxxxxx> wrote:
How may operators and operands does (typename) expression has?

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? */
}
.



Relevant Pages

  • Re: unsigned right shift casts to int automatically!!!
    ... casts the data to int and extends it to int in unsigned form. ... Arithmetic operations with byte operands are required by the JLS to do ... "Binary numeric promotion is not performed on the operands; ... You can do an explicit cast followed by a mask to kill the sign extension: ...
    (comp.lang.java.programmer)
  • Re: What is wrong with this transformation?
    ... derived column transformation. ... Something about casting operands... ... input column or the result of a cast, and cannot be used with the ...
    (microsoft.public.sqlserver.dts)
  • Re: First Program
    ... double compute_mean(int *arr, int arr_length) ... this is one of the few cases where a cast is justified. ... operator takes two operands of the *same* numeric type, ... I might cast both operands: ...
    (comp.lang.c)
  • Re: integer division
    ... > int i, pk, dy, dx, yc, xc, inc, temp; ... The fact that you cast the result afterwards does not change this. ... The int result, with no fractional part, will be converted to float ... If you convert either of the operands to float by a cast, ...
    (comp.lang.c)
  • Re: byte to int casting question
    ... Any time you do an addition the operands ... >> will be promoted to int or long or float or double as appropriate. ... The int 4 is cast to a byte, the int 3 is cast to a byte, the presence of ... The 7 fits into a byte with no loss of precision so byte b is initialised to ...
    (comp.lang.java.programmer)