Escape sequences for printf() defined by SVID

Wm E Davidsen Jr davidsen at crdos1.crd.ge.COM
Thu Jan 4 04:43:53 AEST 1990


In article <1990Jan3.144808.6319 at sssab.se> sveer at sssab.se (Sven L Eriksson) writes:
| Everybody knows that escape sequences like these works fine with printf
| 
| 	printf("\thello\n") ;
| 
| Usually these escape sequences are recognized and converted by the
| compiler.

  If the compiler is one for the C language, ALL escape sequences are
converted to their single character form. Not usually, always.
| 
| However SVID (Issue 2) states that the format string may contain these
| escape sequences. This implies that it is possible for the actual
| format string printf sees to contain the characters '\' and 'n', and
| still be converted into a newline. This whould be very convenient if
| the format string is received from elsewhere, e.g. stdin.

  I hope your misreading this... it isn't common to include stuff like
this, but an error message might well do so. If I define a string as
"xx\\n" it will have two x's, one \, one n, and a terminating zero byte.
That is what you get printed with existing C compilers, and I doubt that
SVID breaks it. For that matter, what has SVID got to do with the C
language, and why are they even mentioning this? X3J11 didn't respecify
the unix calls ;-)
-- 
bill davidsen	(davidsen at crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon



More information about the Comp.std.c mailing list