uint_least32_t is in stdint.h not in inttypes.h

Vincent Lefevre vincent at vinc17.net
Sun Nov 15 22:22:53 UTC 2020

On 2020-11-15 22:21:18 +0100, Felix von Leitner wrote:
> I was trying to compile gmp with my libc, dietlibc, and got an error
> that uint_least32_t is not defined.
> Well, it is defined, and as far as I can tell in the right header file,
> too: stdint.h.
> However, gmp-impl.h reads as follows:
>  155 #if HAVE_INTTYPES_H      /* for uint_least32_t */
>  156 # include <inttypes.h>
>  157 #else
>  158 # if HAVE_STDINT_H
>  159 #  include <stdint.h>
>  160 # endif
>  161 #endif
> Note that stdint.h is in the else clause. dietlibc has both
> inttypes.h and stdint.h.

But ISO C99 says:

  7.8 Format conversion of integer types <inttypes.h>

  The header <inttypes.h> includes the header <stdint.h> [...]

So, including <inttypes.h> if present should be sufficient, and
this is what the above code does.

That said, for C99 implementations, the #if tests would be useless,
so that the above code is also designed for non-C99 implementations,
which may have <inttypes.h> and <stdint.h> with a behavior different
from C99, i.e. <inttypes.h> will not necessarily include <stdint.h>
(but this also means that <stdint.h> will not necessarily have

> Proposed fix: Move the #if HAVE_STDINT_H outside the previous #if.

Indeed, including both headers independently (when they are available)
may be the best way to have a chance to get uint_least32_t.

Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

More information about the gmp-bugs mailing list