issue with Microsoft compiler

Niels Möller nisse at
Mon Feb 13 11:35:16 CET 2023

Marc Glisse <marc.glisse at> writes:

> I think changing it in public headers (gmp.h, gmpxx.h) is the
> important part, changing it in internal source files is less of an
> issue.

Good point. I got the impression that someone was building GMP with
-Werror. Getting this by just *using* gmp and including gmp.h is
a different setting with different tradeoffs.

It might make some sense to add something like

  #ifdef _MSC_VER
  # pragma warning(disable:4146)

to the installed gmp.h, if that is deemed not too brittle (I don't know
how stable warning numbers are, or if there's some better way). I got
_MCS_VER from a quick look at

> To be fair, it is often not the user who enables /WX but the Visual
> Studio IDE that enables /SDL by default, which turns some warnings
> that Microsoft deems relevant to security into errors. And Microsoft's
> reply in bug reports is "disable this option if you don't like it".

Is the pragma a documented / recommended way to disable the warning?

The warning would make more sense to me if narrowed to cases where the
result is assigned/used in some signed context where it matters for the
result. E.g., if long is a larger size than int, warning for code like
below seems a lot more reasonable than warning for gmp's use case.

  #include <stdio.h>
  int main (int argc, char **argv) {
    unsigned int x = 17;
    signed long y = -x;
    printf("y = %ld\n", y);
    return 0;

Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.

More information about the gmp-bugs mailing list