Date: Tue, 1 Dec 2015 23:03:56 -0600 From: Benjamin Kaduk <bjkfbsd@gmail.com> To: Craig Rodrigues <rodrigc@freebsd.org> Cc: Bryan Drewery <bdrewery@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org> Subject: Re: svn commit: r291637 - head/cddl/contrib/opensolaris/cmd/plockstat Message-ID: <CAJ5_RoDafvtrcJm-uHHpD-Nps-vg6JaQGOJZvrbMp8OuwnUvJA@mail.gmail.com> In-Reply-To: <CAG=rPVfgid=htd0s-THye4TssVg9GJ7T=BXnbfRB6T2u3eOUcQ@mail.gmail.com> References: <201512020211.tB22BcUB082864@repo.freebsd.org> <CAG=rPVfgid=htd0s-THye4TssVg9GJ7T=BXnbfRB6T2u3eOUcQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Dec 1, 2015 at 10:18 PM, Craig Rodrigues <rodrigc@freebsd.org> wrote: > On Tue, Dec 1, 2015 at 6:11 PM, Bryan Drewery <bdrewery@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ5_RoDafvtrcJm-uHHpD-Nps-vg6JaQGOJZvrbMp8OuwnUvJA>