Subject: Re: printf formats again
To: John F. Woods <>
From: David Weaver <>
List: current-users
Date: 11/14/1996 09:10:50
On Wed, 13 Nov 1996, John F. Woods wrote:

> course), I wonder if there's room for a different tack on extended
> printf formats.

> printf format.  On the other hand, I personally loathe the 8-bit
> centrism implicit in exposing a set of bit-widths (even though there
> probably will never again be a 9 or 10 bit byte), and that still

I agree; I have always wanted to design a microprocessor with an 11 bit
byte and 33 bit word size, just for spite. 

> doesn't solve the desire to print things like off_t or fseek_t without
> admitting explicitly how long they are (and, of course, there's always
> the possibility that a given program will outlive the 64-bit limit and
> become embarrassed when off_t requires %I128...).

How long they are?  The concept of length implies that these can always be
treated as integral types.  They may be (or become) complex types.

> Perhaps, though, at least the popular typedef'd types could use the
> same kind of extension mechanism; %Ioff_t for off_t (however wide your

> supplied types, you have to update printf.c (and friends) every time

Essentially, one is trying to convert one data type to another data type. 
In this case, the target type is a vector of characters which represent
the source type in a human readable form.  As you pointed out, it would be
an aggrivating burden to require an algorithm (printf) to handle every
data type conversion that ever existed or ever will exist.

So, why not let the data convert itself?  Of course, this isn't easy in C
which does not support encapsulation and methods and such.  Still it can
be done.  How about declaring a conversion method for each opaque type in
the system?  It would be the responsibility of the creator of the type to
create the method in the same scope as the type.  For example, following
the declaration of off_t could be a function of the form

  char *off_t_to_string(off_t p);

To print the type, you would simply use something like:

  off_t p;
  /* p = whatever; */
  printf("Offset is %s\n", off_t_to_string(p));

> Thank goodness C++ solves this problem.  Mostly.

Encapsulation is good.