On Thu, Sep 20, 2007 at 12:46:11PM -0700, Simion Stoilow wrote:

> While running the following code I was surprised to see a different
> result from the one I expected:
> 
>     int a = 10;
>     double b = 5;
> 
>     int sz_ret = sizeof (a>b? a:b);
> 
> In this case, while (to me) the obvious result would have been sz_ret
> = 4 (as the result of the exp 'a>b? a:b' is a) after running this code
> under VS6 sz_ret = 8.
> 
> Any reason for this behavior?

The comparison of 'a' with 'b' requires the compiler to implicitly
typecast 'a' to a double.  The ?: ternary operator then uses this value
as the return result.

Reply via email to