Torbjorn Granlund tg at gmplib.org
Mon Jun 10 13:28:26 CEST 2013

Marc Glisse <marc.glisse at inria.fr> writes:

  according to the C standard, USHRT_MAX has type int (or unsigned int
  if short and int have the same size). __GMP_USHRT_MAX has type
  unsigned short. GMP sometimes defines USHRT_MAX as __GMP_USHRT_MAX,
  and always assumes that USHRT_MAX has type unsigned short (in printf
  in particular). This seems to only affect the testsuite, but it would
  still be nice to fix (some compilers give warnings).
I suppose we should not deviate from the standard.

  Should __GMP_USHRT_MAX be defined to ((unsigned
  int)current_definition) and the 'h' in printf format strings removed,
  or should USHRT_MAX be cast to (unsigned short) where needed? Or
  something else?

I think 'short' arguments to stdarg functions like printf will be
promoted to int.

The h printf modifier then only has the effect of truncating the int
argument to the range of 'short'.  (Using h will only ever invoke
undefined behaviour, unless followed by o,u,x,or X...)


More information about the gmp-bugs mailing list