🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #6117

Re: printf format

#6117
From: John Macdonald
Date: Fri, 15 Dec 1989 22:09
32 lines
2119 bytes
In article <15430@haddock.ima.isc.com> karl@haddock.ima.isc.com (Karl Heuer) writes:
>In article <5761@ozdaltx.UUCP> root@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@eci386
Technical Details
Message-ID: <1989Dec15.220904.2706@eci386.uucp>
Path: arc1-ca.pugleaf.net!utzoo!attcan!lsuc!eci386!jmm
References: <5761@ozdaltx.UUCP> <15430@haddock.ima.isc.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!lsuc!eci386!jmm
From: jmm@eci386.uucp (John Macdonald)
Newsgroups: comp.std.c
Subject: Re: printf format
Message-ID: <1989Dec15.220904.2706@eci386.uucp>
Date: 15 Dec 89 22:09:04 GMT
References: <5761@ozdaltx.UUCP> <15430@haddock.ima.isc.com>
Reply-To: jmm@eci386.UUCP (John Macdonald)
Organization: R. H. Lathwell Associates: Elegant Communications, Inc.
Lines: 33