[Main]
Title=__builtin_choose_expr

[Top]
<CODE><I>type</I> __builtin_choose_expr (const_exp, exp1, exp2);</CODE>
<BR><BR>
You can use the built-in function __builtin_choose_expr to
evaluate code depending on the value of a constant expression.  This
built-in function returns <I>exp1</I> if <I>const_exp</I>, which is a
constant expression that must be able to be determined at compile time,
is nonzero.  Otherwise it returns 0.
<BR><BR>
This built-in function is analogous to the <CODE>?&nbsp;:</CODE> operator in C,
except that the expression returned has its type unaltered by promotion
rules.  Also, the built-in function does not evaluate the expression
that was not chosen.  For example, if <I>const_exp</I> evaluates to true,
<I>exp2</I> is not evaluated even if it has side-effects.
<BR><BR>
This built-in function can return an lvalue if the chosen argument is an
lvalue.
<BR><BR>
If <I>exp1</I> is returned, the return type is the same as <I>exp1</I>'s
type.  Similarly, if <I>exp2</I> is returned, its return type is the same
as <I>exp2</I>.
<BR><BR>
Example:
<PRE>#define foo(x)                                                    \
  __builtin_choose_expr (                                         \
    __builtin_types_compatible_p (typeof (x), double),            \
    foo_double (x),                                               \
    __builtin_choose_expr (                                       \
      __builtin_types_compatible_p (typeof (x), float),           \
      foo_float (x),                                              \
      /* The void expression results in a compile-time error  \
         when assigning the result to something.  */          \
      (void)0))
</PRE>
<B>Note:</B> The
unused expression (<I>exp1</I> or <I>exp2</I> depending on the value of
<I>const_exp</I>) may still generate syntax errors.  This may change in
future revisions.
