On 02/26/2017 07:21 AM, Gerald Pfeifer wrote:
On Sun, 19 Feb 2017, Gerald Pfeifer wrote:
That was quite a bit; thanks for doing that, Jakub!
In the patch below I try to streamline language a bit, document options
being implied by -Os (in addition to -O2 or higher), fix grammar in a few
places, and change a textual link to being a real one.
I have _not_ applied this yet, and would appreciate your feedback.
I did another two passes through this, making a few more simplifications
and changes, and committed it.
If you see anything beyond it, or changes you disagree with, let me know!
@@ -525,8 +524,8 @@
<li>New <code>__builtin_add_overflow_p</code>,
<code>__builtin_sub_overflow_p</code>,
<code>__builtin_mul_overflow_p</code> built-in functions have been added.
- These work similarly to earlier added built-in functions without the
- <code>_p</code> suffix, but don't actually store the result of the
+ These work similarly to their siblings without the
+ <code>_p</code> suffix, but do not actually store the result of the
arithmetics anywhere, just return whether the operation would overflow.
These builtins allow easy checking for overflows e.g. in C++
<code>constexpr</code> contexts.</li>
Sorry to be jumping in so late. I only noticed this bit now.
I would suggest to say that these new built-ins evaluate to integer
constant expressions when their arguments do. Not all C programmers
are familiar with C++ constexpr so they may not understand the use
use case. The request for these built-ins also came from a C user
and was specifically motivated by avoiding -Woverflow warnings so
adding an example demonstrating that might be helpful as well.
Something like this:
... Calls to these built-ins with integer constant arguments
evaluate to integer constants expressions.</p>
<p>For example, in the following, <code>c</code> is assigned
the result of <code>a * b</code> only if the multiplication
does not overflow, otherwise it is assigned the value zero.
The multiplication is performed at compile-time and without
triggering a <code>-Woverflow</code> warning.
<blockquote>
<pre>enum {
a = 12345678,
b = 87654321,
c = __builtin_mul_overflow_p (a, b, a) ? 0 : a * b
};</pre>
</blockquote></li>
Martin