Path: 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 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 (%) and then call a function to carry out the action that corresponds to . The function is found in a table indexed by . 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