Pádraig Brady wrote:
The issue I have with the example is that INT_MULTIPLY_WRAPV() takes 3 arguments, while only 2 are provided.
Ouch, right! I didn't see that. Fixed with the attached.
In case gcc decides to continue to warn in this case, I suppose we could avoid the undefined code by promoting to a wider type and explicitly truncating the result (though that might need __int128 if available for your new 64 bit case).
I didn't want to go that route, due to the portability hassles of dealing with __int128 support. (Besides, if we wanted to deal with __int128, we'd want to deal with it as an operand type too, which means we'd need __int256.... :-)
>From a214964682085cb1e57a77db082f5e9387646f9c Mon Sep 17 00:00:00 2001 From: Paul Eggert <egg...@cs.ucla.edu> Date: Thu, 17 Dec 2015 23:06:29 -0800 Subject: [PATCH] intprops: comment fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lib/intprops.h: Fix comment. Reported by Pádraig Brady in: http://lists.gnu.org/archive/html/bug-gnulib/2015-12/msg00013.html --- ChangeLog | 4 ++++ lib/intprops.h | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4fb4b97..3945c58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2015-12-17 Paul Eggert <egg...@cs.ucla.edu> + intprops: comment fix + * lib/intprops.h: Fix comment. Reported by Pádraig Brady in: + http://lists.gnu.org/archive/html/bug-gnulib/2015-12/msg00013.html + intprops-test: work around GCC bug 68971 Problem reported by Pádraig Brady in: http://lists.gnu.org/archive/html/bug-gnulib/2015-12/msg00011.html diff --git a/lib/intprops.h b/lib/intprops.h index 8fff86d..ecafaf7 100644 --- a/lib/intprops.h +++ b/lib/intprops.h @@ -272,9 +272,10 @@ Example usage, assuming A and B are long int: - long int result = INT_MULTIPLY_WRAPV (a, b); - printf ("result is %ld (%s)\n", result, - INT_MULTIPLY_OVERFLOW (a, b) ? "after overflow" : "no overflow"); + if (INT_MULTIPLY_OVERFLOW (a, b)) + printf ("result would overflow\n"); + else + printf ("result is %ld (no overflow)\n", a * b); Example usage with WRAPV flavor: -- 2.5.0