"%#s"?

Chris Torek chris at mimsy.UUCP
Sun May 29 05:00:36 AEST 1988


In article <AWbStey00Uk4E0S14d at andrew.cmu.edu> jk3k+ at andrew.cmu.edu
(Joe Keane) writes:
>It would be nice for printf et al.  to have a %#s format specifier,
>to convert unprintable characters into backslash escapes.  Thus
>	printf ("%#s", "\b\fhi\n\207");
>would be equivalent to
>	printf ("\\b\\fhi\\n\\207");

There are many things that might be nice: Roman numerals (both upper
and lower case: %r and %R are both free), unsigned decimal conversions,
chopped vs. rounded (and up or down?) floating numbers, and so forth.
But some of us feel that printf is already too complex.  (Keith Bostic
and I spent a week arguing over exactly what printf is supposed to do
in odd cases, poring over ANSI drafts, and coming up with perverse test
cases like `%500.400g' or `%#0500x'.  The 4.3BSD _doprnt fails the
huge-fill-count tests, incidentally.)

>Has anyone else thought of this?

Yes.

>Is it a good idea?

Possibly.  You can always your own code for it.  (Probably the best way
to augment printf, if it is to be augmented at all, is to add a `%'
conversion that calls a function, passing it the various flags and
specifiers and the FILE and va_list arguments.  The function would
return the number of characters transferred.  At least, that would fit
well with our new _doprnt.)

>Can it be put in the standard?

Anything that is not an `editorial change' is probably not going
to make it.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list