Context reinserted...

[  int a = 10;
   double b = 5;
   int sz_ret = sizeof (a>b? a:b);  ]

> > > After a bit of experimentation it seems to me that
> > > actually the result of the conditional expression is cast
> > > to the 'roomiest' type (which is variable's a type, double)

No. What you mean is there is an implicit conversion.

Casts, or more formally cast operators, are syntactical
constructs. They are not implicit.

[You should also avoid the word 'typecast' since it is ambiguous
and often loosely used.]

> > > thus the result 8 bytes -> sizeof (double).
> > 
> > I don't think you can use sizeof on an expression like
> > that... what does the standard say?

The standard says you can. In fact, there aren't too many
types or expressions that you can't use sizeof on.

Simion Stoilow <[EMAIL PROTECTED]> wrote:
> I don't see why you cannot use sizeof on such an expression.
> The conditional expression's result is evaluated to a constant

No. There is no evaluation of the operand, be it constant or
otherwise. [See single noted exception elsethread.]

> on which the sizeof operator is applied...
> Nevertheless, I don't have a copy of the standard so I can
> only make assumptions.

No, you have another choice. Obtain the standard, or at least
a draft thereof. That said, good books like K&R2 are probably
better because the standard is no walk in the park. ;-)

> Didn't find much about this on the internet either.

I tried a google search starting on keywords: ternary operator 
expression type. First hit was <http://en.wikipedia.org/wiki/%3F:>
which had the answer half way down the page. [Although the
link to Arithmetic Promotion is missing.]

-- 
Peter

Reply via email to