Subject: Re: Printing of off_t and size_t values
To: Martin Husemann <martin@duskware.de>
From: Luke Mewburn <lukem@netbsd.org>
List: tech-misc
Date: 01/20/2003 21:11:52
On Mon, Jan 20, 2003 at 10:47:51AM +0100, Martin Husemann wrote:
| A short discussion after a recent commit on source-changes brought
| this topic up again and I tried to find all affected files (there
| are 235) - and then noticed share/misc/style is among them. It
| suggests:
|
| /*
| * To printf 64 bit quantities, use %ll and cast to (long long).
| */
| printf("The size of %s is %lld\n", p, (long long)sb->st_size);
|
| Nowadays we can do better. I suggest to change this into:
|
| /*
| * To printf size_t quantities, use %zd:
| */
| printf("The size of %s is %zd\n", p, sb->st_size);
|
| /*
| * To printf off_t (or other 64 bit) quantities, use PRId64
| * from <inttypes.h>:
| */
| printf("Read error at offset %" PRId64 "\n", o);
|
| Is that OK? One option is to leave out the first part and use PRId64
| (and friends) always.
I prefer the latter only; from a portability PoV it's much easier to
provide replacement definitions for PRId64 (et al) than replace "%z[du]"
in random printf(3) format args...
| I volunteer to change all occurances in-tree to whatever we agree
| upon (skiping gnu/dist).
And crypto/dist and dist and ...
Luke.