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

2015-12-01 Thread Benjamin Kaduk
On Tue, Dec 1, 2015 at 10:18 PM, Craig Rodrigues 
wrote:

> On Tue, Dec 1, 2015 at 6:11 PM, Bryan Drewery 
> 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
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


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

2015-12-01 Thread Craig Rodrigues
On Tue, Dec 1, 2015 at 6:11 PM, Bryan Drewery  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.

--
Craig
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"