svn commit: r291637 - head/cddl/contrib/opensolaris/cmd/plockstat

Benjamin Kaduk bjkfbsd at gmail.com
Wed Dec 2 05:03:58 UTC 2015


On Tue, Dec 1, 2015 at 10:18 PM, Craig Rodrigues <rodrigc at freebsd.org>
wrote:

> On Tue, Dec 1, 2015 at 6:11 PM, Bryan Drewery <bdrewery at freebsd.org>
> wrote:
>
> > -               (void) snprintf(buf, size, "%#lx", addr);
> > +               (void) snprintf(buf, size, "%#lx", (unsigned long)addr);
> >                 return (0);
> >
>
> In the past when I've hit these types of problems,
> I have found that using %#jx and casting to (uintmax_t) instead seemed to
> work
> consistently across different platforms, so you might want to do that here.
> There are lots of examples in the tree of this pattern.
>

Any sort of cast will usually work, provided the casted-to type matches the
format string.
The main issue is when one tries to avoid a cast, in which case the
fundamental type corresponding to the abstract type of the variable being
printed can be different across different platforms.  (Some sense is needed
to ensure that the cast does not truncate the range of accessible values,
of course, which is where [u]intmax_t comes in.)

-Ben


More information about the svn-src-head mailing list