[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about portability guidelines

From: Paul Eggert
Subject: Re: Question about portability guidelines
Date: Tue, 3 Jan 2017 16:33:24 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1

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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]