Re: [patch] Use inttypes macros for size_t format string
- Subject: Re: [patch] Use inttypes macros for size_t format string
- From: Tilo Eckert <tilo.eckert@xxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Wed, 22 Jan 2020 17:40:04 +0100
- To: libssh@xxxxxxxxxx
Am 22.01.2020 um 13:56 schrieb g4-lisz@xxxxxxxxxxxx:
> For Windows I can find documentation of "z" as supported spezifier:
> But not sure since when this is supported.
Apparently, %zu is supported since VS 2015 (or 2013?), %Iu is the older
MS-specific alternative. Support for ANSI C99 still seems not to be 100%
complete in VS.
> But anway: What is the advantage of using typecasts instead of a format
> spezifier macro (see my patch)? You still have to use OS specific type
> casts. Or I'm understanding this wrong?
There is no printf format specifier macro for size_t in standard
headers. The PRIdS macro in priv.h defines a format specifier for
printing a ssize_t. We would need a PRIuS macro (`Iu` on Windows, `zu`
everywhere else) as you suggested in an earlier email because size_t is
unsigned. However, I'm not 100% certain whether this works in all build
environments. If you get this macro wrong, not all compilers will warn
you about a bad format string.
A safe, headache-free, C89 compatible, but not as pretty alternative
that will not break in compiler environments of the last 20+ years:
printf("%llu", (long long unsigned) size)
Archive administrator: email@example.com