Subject: Re: printf formats again
To: Don Lewis <Don.Lewis@tsc.tdk.com>
From: John F. Woods <email@example.com>
Date: 11/17/1996 22:14:02
> } > Maybe, but I'd personally far prefer something like
> } > printf("%B*", sizeof(off_t), (off_t) foo);
> } > This should solve the problem for user-supplied types too.
> } I like this idea, a lot better than anything that involves having
> } printf parse the strings looking for type names and then switching
> } based on the type. That's just too inflexible.
As someone pointed out, there's even existing practice for a user-extensible
version which can be made as obscenely flexible as you can stomach. That
may be going way overboard, though.
> But this only works if the arguments aren't composite types. If
> you wanted to have a 64 bit off_t but didn't have compiler support
> for any 64 bit integral types, you'd be out of luck.
Because off_t is required by POSIX to be an integral type, if your port
MUST have 64 bit file offsets, then your compiler MUST support 64 bit
integral types; that's just part of being a compilation system vendor.
If the compiler you start with doesn't have them, it has to before you're
To elaborate on Greg's idea, perhaps the data-width could be incorporated
as a printf format modifier; where you currently can put either 'h' or 'l'
to signal short or long int (i.e. %hd, %lx, etc.) [and 'q' for quad, of
course], add 'B' to say that a word of type size_t should be read from the
argument list to give the number of bytes, which must be one of the
compiler's offered types (or maybe 'S' to stand for size_t, but that's
too easily visually confused with 's'; perhaps '~' for those who'd like
to use 'B' for "binary" and not "bytes"?). (And if you document it as
taking a 'sizeof' value, you could even have -Wformat give a warning
message if the value isn't literally 'sizeof expr-or-(type)'...)