(short)1 + (int)1 type?

as I think
(short)1 + (int)1
should be converted to (int)2 ?

again to the “call to ‘max’ is ambiguous” questions. In the script
[html]
short c = 1;
m = max( 0, 512 - abs(c - 512));
[/html]
both arguments should have (int) type?

Unfortunately, they haven’t. OpenCL (1.0, page 177) specifies the abs function as:

The conversions take place in the following way

(step 1) max( <int> , <int> - abs( <short> - <int> )

(step 2) max( <int> , <int> - abs( <int> )

(step 3) max( <int> , <int> - <uint> )

(step 4) max( <int> , <uint> )

I’m programming C++ more often than C(99), but I am confident that the conversion rules are the same:

If an expression (here -) involves a signed and an unsigned integral, the type of the expression depends on the range of the types.

  • If the whole range of the unsigned type can be represented by the signed type (like in with 8 bit char), the expression yields the signed type.

  • If this is not the case ( has values that cannot be represented by ), the expression yields the unsigned type.

That conversion is neither intuitive, not portable, but it’s the C way (e.g. - is typically on 64 bit and on 32 bit machines).

thank you.
I can just remember, not understand the rule because (int) also has (negative) values that cannot be represented by (uint).