This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Documentation bug for __builtin_choose_expr


On Mon, 22 Nov 2004, Jamie Lokier wrote:

> The documentation for __builtin_choose_expr says:
> 
>  -- Built-in Function: TYPE __builtin_choose_expr (CONST_EXP, EXP1, EXP2)
>      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 EXP1 if CONST_EXP, which is a
>      constant expression that must be able to be determined at compile
>      time, is nonzero.  Otherwise it returns 0.
> 
>      This built-in function is analogous to the `? :' 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 CONST_EXP
>      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>      evaluates to true, EXP2 is not evaluated even if it has
>      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>      side-effects.
>      ^^^^^^^^^^^^^
> 
> The way this is written implies that the underscored behaviour is
> different from the `? :' operator in C.

I'd think the idea is actually to say that it is different from normal 
functions (built-in and otherwise), which inevitably evaluate all their 
arguments before calling the function.  (Although the syntax is that of a 
built-in function, the implementation is that of a new keyword 
__builtin_choose_expr handled specially in the parser.)  Perhaps it should 
say "Unlike most built-in functions, but like the ? : operator, ...".

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]