printf format

John Macdonald jmm at eci386.uucp
Sat Dec 16 09:09:04 AEST 1989


In article <15430 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:
>In article <5761 at ozdaltx.UUCP> root at ozdaltx.UUCP (root) writes:
>>[Can printf() format numbers with embedded commas?]
>
>Not in K&R or ANSI C, though it's conceivable that some vendor has added it as
>an extension.

 [...]

>>If printf does not have this ability, it should be added.

>I think a better idea is to have a separate function to do this type of
>formatting, then print it with %s.  (Just like you have to do with a time_t,
>for example, to make it print in a human-readable format.)  I suspect this is
>what the Committee had in mind.

It's too late for this round of the ANSI spec (and perhaps too far
from existing practice anyhow), but the method I have used anytime
I've had to implement my own printf family of routins for a system
is to have the low-level format scanner collect a % sequence
(%<opt_stuff><char>) and then call a function to carry out the action
that corresponds to <char>.  The function is found in a table indexed
by <char>.  It is passed arguments indicating provided (or default)
values for min_width, max_width, lead_zero, left_justify, and arg_pointer,
and returns the updated arg_pointer as return value (I was doing this
before varargs came onto the scene)).  By providing a get and a set
routine to inspect and modify entries in the table, a number of useful
capabilities became available - most usefully, program-defined extensions
to the printf format codes - e.g. %T to print a symbol table entry.
-- 
80386 - hardware demonstrating the fractal nature of warts.   | John Macdonald
EMS/LIM - software demonstrating the fractal nature of warts. |   jmm at eci386



More information about the Comp.std.c mailing list