* Documentation bug for __builtin_choose_expr
@ 2004-11-22 8:06 Jamie Lokier
2004-11-22 10:41 ` Joseph S. Myers
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Jamie Lokier @ 2004-11-22 8:06 UTC (permalink / raw)
To: gcc
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.
But the `? :' operator does not evaluate the expression that was not
chosen either. If the condition evaluates to true, EXP2 is not
evaluated in `COND ? EXP1 : EXP2'.
It would be better to replace that paragraph with:
This built-in function is analogous to the `? :' operator in C,
except that the expression returned has its type unaltered by
promotion rules.
If there is some other effect of __builtin_choose_expr, for example if
it were to inhibit compilation or warnings in the unselected branch in
some way, it would be useful to mention that. I don't know of any
such effects. (Inhibiting warnings in the unselected branch and
promising to not expand large inline functions in that branch would be
a useful addition imho).
-- Jamie
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Documentation bug for __builtin_choose_expr
2004-11-22 8:06 Documentation bug for __builtin_choose_expr Jamie Lokier
@ 2004-11-22 10:41 ` Joseph S. Myers
2004-11-22 10:42 ` Jamie Lokier
2004-11-22 12:21 ` Andreas Schwab
2004-11-22 20:45 ` Kai Henningsen
2 siblings, 1 reply; 8+ messages in thread
From: Joseph S. Myers @ 2004-11-22 10:41 UTC (permalink / raw)
To: Jamie Lokier; +Cc: gcc
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)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Documentation bug for __builtin_choose_expr
2004-11-22 10:41 ` Joseph S. Myers
@ 2004-11-22 10:42 ` Jamie Lokier
0 siblings, 0 replies; 8+ messages in thread
From: Jamie Lokier @ 2004-11-22 10:42 UTC (permalink / raw)
To: Joseph S. Myers; +Cc: gcc
Joseph S. Myers wrote:
> Perhaps it should
> say "Unlike most built-in functions, but like the ? : operator, ...".
Yes, I agree.
Here is the whole suggested replacement paragraph:
This built-in function is analogous to the `? :' operator in C,
except that the expression returned has its type unaltered by
promotion rules. Unlike most built-in functions, but like the
`? :' operator, this 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 change is:
Also, the...
to
Unlike most built-in functions, but like the `? :' operator, this...
Would anyone who updates in documentation care to make this change?
-- Jamie
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Documentation bug for __builtin_choose_expr
2004-11-22 8:06 Documentation bug for __builtin_choose_expr Jamie Lokier
2004-11-22 10:41 ` Joseph S. Myers
@ 2004-11-22 12:21 ` Andreas Schwab
2004-11-22 14:44 ` Jamie Lokier
2004-11-22 20:45 ` Kai Henningsen
2 siblings, 1 reply; 8+ messages in thread
From: Andreas Schwab @ 2004-11-22 12:21 UTC (permalink / raw)
To: Jamie Lokier; +Cc: gcc
Jamie Lokier <jamie@shareable.org> writes:
> 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 don't see that. For me the word "also" implies "another analogousness".
IMHO this is fact is worth noting because the usual rules for function
calls in C is to evaluate all its arguments first, whereas this builtin
does not do that even though it uses a function-like notation.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, MaxfeldstraÃe 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Documentation bug for __builtin_choose_expr
2004-11-22 12:21 ` Andreas Schwab
@ 2004-11-22 14:44 ` Jamie Lokier
2004-11-22 15:02 ` Andreas Schwab
0 siblings, 1 reply; 8+ messages in thread
From: Jamie Lokier @ 2004-11-22 14:44 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gcc
Andreas Schwab wrote:
> > 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 don't see that. For me the word "also" implies "another analogousness".
It depends how you parse it.
> IMHO this is fact is worth noting because the usual rules for function
> calls in C is to evaluate all its arguments first, whereas this builtin
> does not do that even though it uses a function-like notation.
I agree it's worth noting. What do you think of the alternative wording
put forth by Joseph S. Myers, which I find clearer? This is it:
This built-in function is analogous to the `? :' operator in C,
except that the expression returned has its type unaltered by
promotion rules. Unlike most built-in functions, but like the
`? :' operator, this 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.
I can't check in the change, perhaps someone else can.
-- Jamie
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Documentation bug for __builtin_choose_expr
2004-11-22 14:44 ` Jamie Lokier
@ 2004-11-22 15:02 ` Andreas Schwab
2004-11-22 18:58 ` Robert Dewar
0 siblings, 1 reply; 8+ messages in thread
From: Andreas Schwab @ 2004-11-22 15:02 UTC (permalink / raw)
To: Jamie Lokier; +Cc: gcc
Jamie Lokier <jamie@shareable.org> writes:
> This built-in function is analogous to the `? :' operator in C,
> except that the expression returned has its type unaltered by
> promotion rules. Unlike most built-in functions, but like the
> `? :' operator, this 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.
IMHO, "but like the `? :' operator" could be removed without any negative
impact (anyone who doesn't know how the ?: operator should not look at
builtins either :-) ).
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, MaxfeldstraÃe 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Documentation bug for __builtin_choose_expr
2004-11-22 15:02 ` Andreas Schwab
@ 2004-11-22 18:58 ` Robert Dewar
0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 2004-11-22 18:58 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Jamie Lokier, gcc
Andreas Schwab wrote:
> Jamie Lokier <jamie@shareable.org> writes:
>
>
>> This built-in function is analogous to the `? :' operator in C,
>> except that the expression returned has its type unaltered by
>> promotion rules. Unlike most built-in functions, but like the
>> `? :' operator, this 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.
>
>
> IMHO, "but like the `? :' operator" could be removed without any negative
> impact (anyone who doesn't know how the ?: operator should not look at
> builtins either :-) ).
Why remove it? It only makes things clearer ... Documentation is about
making things clear, we are not writing a language standard here, where
redundancy is to be avoided. Perhaps it would make things clearer to put
this parenthetical remark in parentheses
>
> Andreas.
>
>> This built-in function is analogous to the `? :' operator in C,
>> except that the expression returned has its type unaltered by
>> promotion rules. Unlike most built-in functions (but like the
>> `? :' operator), this 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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Documentation bug for __builtin_choose_expr
2004-11-22 8:06 Documentation bug for __builtin_choose_expr Jamie Lokier
2004-11-22 10:41 ` Joseph S. Myers
2004-11-22 12:21 ` Andreas Schwab
@ 2004-11-22 20:45 ` Kai Henningsen
2 siblings, 0 replies; 8+ messages in thread
From: Kai Henningsen @ 2004-11-22 20:45 UTC (permalink / raw)
To: gcc
jamie@shareable.org (Jamie Lokier) wrote on 22.11.04 in <20041122042652.GA26998@mail.shareable.org>:
> 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.
*************************************************
Surely that should be "Otherwise it returns EXP2"?!
MfG Kai
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2004-11-22 19:17 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-22 8:06 Documentation bug for __builtin_choose_expr Jamie Lokier
2004-11-22 10:41 ` Joseph S. Myers
2004-11-22 10:42 ` Jamie Lokier
2004-11-22 12:21 ` Andreas Schwab
2004-11-22 14:44 ` Jamie Lokier
2004-11-22 15:02 ` Andreas Schwab
2004-11-22 18:58 ` Robert Dewar
2004-11-22 20:45 ` Kai Henningsen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).