In a well-known article by Ken Thompson, ( http://users.ece.cmu.edu/~ganger/712.fall02/papers/p761-thompson.pdf )
in figure 1, that formats printf with decimal %d
printf("\t%d, \n", s[i]);
Why would that be done? Shouldn't it have been %c with character format? Why not? Was printf different during that time? Which version of C is the one in figure 1 in the article?
char
is an integer type, and such printable with format specifiers for integers. Type promotion rules cause it to be converted toint
when passed on a variadic argument list, which makes%d
a valid format specifier forchar
. Strictly speaking,%hhd
is preferred forchar
, but this might have not existed back then; this is probably the only part that might be retro-specific.