Re: 2 minor issues on Windows
There is some sort of sick competition between certain compilers to have the most warnings for valid C. I don't think we should play their game, and as a result obfuscate the GMP sources. Incidantally, arithmetic on unsigned types is well-defined. Unlike that of signed types. Should not these compilers warn about *every* arithmetic operation on signed integers? Certainly, it should warn about signed negation, unless it can prove the negated value is not INT_MIN, as -INT_MIN is undefined in two's complement representation... int foo (int a, int b) { return a + b - 1; } $ clank foo.c warning: signed addition might overflow and yield undefined results warning: signed subtraction might overflow and yield undefined results -- Torbjörn Please encrypt, key id 0xC8601622 ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Re: 2 minor issues on Windows
Marco Bodrato writes: - *__gmp_rp = (- *__gmp_up) & GMP_NUMB_MASK; + *__gmp_rp = (1 + ~ *__gmp_up) & GMP_NUMB_MASK; Let's please not do this. There is some sort of sick competition between certain compilers to have the most warnings for valid C. I don't think we should play their game, and as a result obfuscate the GMP sources. -- Torbjörn Please encrypt, key id 0xC8601622 ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Re: 2 minor issues on Windows
Ciao, Il 2022-02-03 08:50 ni...@lysator.liu.se ha scritto: George Woltman writes: Minor issue #2 (I should have reported this years ago, sorry): In gmp.h, these lines: mpn_neg (mp_ptr __gmp_rp, mp_srcptr __gmp_up, mp_size_t __gmp_n) [...] *__gmp_rp = (- *__gmp_up) & GMP_NUMB_MASK; The last line generates this compiler warning: warning C4146: unary minus operator applied to unsigned type, result still I can only suggest that you disable or ignore that warning. Operations on unsigned types is well defined by the C standard, and gmp depends on practically all possible corner cases to work according to spec. Maybe we can avoid this in the file gmp.h; it is used during the compiling process of any project using the library... What about the following? --- a/gmp-h.in Fri Mar 11 21:13:20 2022 +0100 +++ b/gmp-h.in Sat Mar 12 23:23:09 2022 +0100 @@ -2234,7 +2234,7 @@ ++__gmp_up; ++__gmp_rp; } - *__gmp_rp = (- *__gmp_up) & GMP_NUMB_MASK; + *__gmp_rp = (1 + ~ *__gmp_up) & GMP_NUMB_MASK; if (--__gmp_n) /* Higher limbs get complemented. */ mpn_com (++__gmp_rp, ++__gmp_up, __gmp_n); For an optimising compiler, there should not be any difference. "+ ~ *" is a funny sequence of operators :-) Ĝis, m ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs