Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 May 2012 20:46:25 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Garrett Cooper <yanegomi@gmail.com>
Cc:        "mdf@FreeBSD.org" <mdf@FreeBSD.org>, "src-committers@freebsd.org" <src-committers@FreeBSD.org>, "svn-src-all@freebsd.org" <svn-src-all@FreeBSD.org>, Dimitry Andric <dim@FreeBSD.org>, "David E. O'Brien" <obrien@FreeBSD.org>, BruceEvans <brde@optusnet.com.au>, "svn-src-head@freebsd.org" <svn-src-head@FreeBSD.org>
Subject:   Re: svn commit: r235797 - head/contrib/gcc
Message-ID:  <20120523203051.J1464@besplex.bde.org>
In-Reply-To: <E8EA81ED-EA81-4ED3-9973-9DE1C2F26C53@gmail.com>
References:  <201205221818.q4MII7lk019626@svn.freebsd.org> <20120523050739.H3621@besplex.bde.org> <CAMBSHm-C7YdU0uPa7aJ6FxDWhZzQiD0_uTj=f1nhV2k5SZ5%2B_A@mail.gmail.com> <4FBC86B3.8020105@FreeBSD.org> <E8EA81ED-EA81-4ED3-9973-9DE1C2F26C53@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 23 May 2012, Garrett Cooper wrote:

> On May 22, 2012, at 11:41 PM, Dimitry Andric <dim@FreeBSD.org> wrote:
>
>> On 2012-05-22 23:07, mdf@FreeBSD.org wrote:
>> ...
>>> We run with the following at Isilon, which is somewhat bogus because
>>> it allows a bit of sloppiness in types, but is also terribly
>>> convenient since it means no casting on printf arguments is needed:
>>
>> Please don't.  If you want to write portable code, use the (admittedly
>> horrible) PRId64 macros instead.

Please don't.  The PRI macros are almost as abominable as long long.

> Agreed, because the patch attached earlier disguises issues with signedness (for one) and I've seen some interesting bugs creep in because of issues like that, an it's painful cleaning up those problems later on (esp. considering that clang will replace gcc not too far down the line)...

Disagreed (except I always notice sign errors in printf formats too.  I once
fixed -Wformat to detect sign errors, but ran away since it found even
more sign errors than size errors.  Now I only notice the sign errors when
a size error turns up).

Apart from being even uglier looking than long long, the PRI macros are
not even usable for printing an averaged typedefed type, since unless
there is a format letter and a corresponding PRI macro for just that
type, you have to peer inside the opaque details of the type to determine
its size and perhaps its signedness and then hard-code the corresponding
PRI macro.  This breaks as soon as the opaque details change and thus
defeats the point of having (semi-)opaque typedefed types.

If a variable's type is known to be 64 bits, then you can hard-code
PRI64 for it.  This breaks as soon as the knowledge becomes out of date.
Since the type isn't typedefed, it is less likely to change, but there
is no guarantee.  Everyone knew that all types were 32 bits and had to
change too much to support 64 bit systems.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120523203051.J1464>