"%#s"?

Karl Heuer karl at haddock.ISC.COM
Fri Jun 3 15:32:31 AEST 1988


In article <1043 at cresswell.quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
>In article <4311 at haddock.ISC.COM>, karl at haddock.ISC.COM (Karl Heuer) writes:
>>Since the result is probably going to be handed to printf anyway, I'd get
>>rid of the width/places arguments and let printf handle them.  This keeps
>>the function simpler.
>
>It also makes it very little use [because the argument may not be terminated
>by a null character]

True.  I think I'd handle it with separate functions, perhaps called
strview(), strnview(), and memview().

>I think we can describe the proposed effect of %#c quite succinctly:
>... both '<S>' and "<S>" would be legal C constants ...

So '\'' and '"' would be escaped, in addition to '\\'?  I hadn't considered
that, but I suppose it makes sense (especially if the application is a
code generator, rather than a debugging routine).

>The effect of %#s would be the effect of the appropriate sequence of %#c
>instances.

Assuming that the C constant "<S>" should represent the argument to %#s, this
may not always be possible: as of the Jan88 dpANS, the only way to write the
two-character string "\x400""3" without using string-pasting is to write the
character '3' in octal or hex, but %#c would want to emit a '3'.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list