%r in printf

mrm at datagen.UUCP mrm at datagen.UUCP
Fri Oct 14 03:11:51 AEST 1983

I was told by a friend that used to work at Bell Labs, that %r was undocumented,
but in the early versions of UNIX (tm).  It was removed around the time, v7
went out.  The way he rememebered it worked was the way I implemented it for
AOS/VS C, put I have heard from others that the DECUS way was the actual way
it was implemted.

For the record, the way AOS/VS C implements %r is to consider the next argument
as a byte pointer to a nested format, any format descriptors within that format
are taken from the next argument(s), rather than taking the next argument as an
address to an argument list.  This means that it can be used as follows:

	#include <ctype.h>

	foo( c )
	char	c;
		printf("C is '%r'\n", isprint(c) ? "%c" : "\\%03o", c );

which would print the argument c as an octal character constant if it was not
printable, and as a normal character constant if it were printable.  This
allows complicated formats to be built on the fly, which otherwise might mean
3 or 4 printf statements and a if thrown in for good measure.

More information about the Comp.lang.c mailing list