On 01/03/2017 04:16 PM, Ben Pfaff wrote: > One strategy is to use PRIdPTR for ptrdiff_t and PRIdMAX or PRIuMAX > (plus a cast) for other types.
PRIdPTR is for intptr_t, not for ptrdiff_t. (An aside: It's typically safer in C to assign to a typed temporary than to cast to the type, as casts are too powerful. This is orthogonal to the long-vs-ptrdiff_t issue.) > In one project of mine (which does not use Gnulib) I introduced a > PRIuSIZE macro. This is not a standard macro, but I don't understand > why not. It's not in C99 because %zu is supposed to suffice, just as %td is supposed to suffice for ptrdiff_t. Of course this does not help for porting to pre-C99 libraries. PRIdPTR etc. are awkward for applications that need to select the format (d, u, x, etc.) in a portable way. For each user-defined integer typedef, one must define a separate macro for d, for u, for x, etc. I do not know why the C standard's authors specified PRIdPTR (e.g., "ld"), PRIuPTR (e.g., "lu"), etc., instead of specifying just PRIPTR (e.g., "l") for the width part only.