"%#s"?

Richard A. O'Keefe ok at quintus.UUCP
Wed Jun 1 16:40:55 AEST 1988


In article <4311 at haddock.ISC.COM>, karl at haddock.ISC.COM (Karl Heuer) writes:
> In article <1039 at cresswell.quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
> >In article <19166 at watmath.waterloo.edu>, rbutterworth at watmath.waterloo.edu (Ray Butterworth) writes:
> >> Perhaps %#s and %#c can be added in future updates to the language.
> >
> >In the mean-time, why not post sources for a
> >	spr_str(char *buffer, int width, int places, char *source)
> 
> 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.  Forget the width argument, which is
admittedly not so important.  The important one is the .places argument,
which serves to terminate the string.  If I want to print the first 20
characters of an array which might not have any NULs nearby, I can do
	printf("%.20s", buffer);
or	printf("%.*s", 20, buffer);
I generally use the second form, as then I can have an expression for the
amount that I want written.  This is especially useful for debugging, when
the bug may involve a clobbered NUL.  And this is precisely where I would
use %#s if it existed.  So it is important that a trial implementation of
this operation should let me bound the source this way.

I think we can describe the proposed effect of %#c quite succinctly:
it writes the shortest sequence <S> of isprint() characters such that
both '<S>' and "<S>" would be legal C constants for which the '<S>'
version would have the same value as its argument, preferring symbolic
forms such as \a to octal forms such as \7.  The effect of %#s would
be the effect of the appropriate sequence of %#c instances.
The effect of %#c on arguments like 'abc' would be implementation-defined.



More information about the Comp.lang.c mailing list