[gnu.gcc] gcc 1.34, can't printf "%"

rusty@GARNET.BERKELEY.EDU (04/20/89)

The following program

main() {
	printf("\%d\n");
}

gets the complaint "warning: unknown escape sequence `\%'".  Is there
some command-line flag I can use or is this a bug?

composer@bu-cs.BU.EDU (Jeff Kellem) (04/20/89)

In article <8904192118.AA09440@garnet.berkeley.edu> rusty@GARNET.BERKELEY.EDU writes:
>The following program
>
>main() {
>	printf("\%d\n");
>}
>
>gets the complaint "warning: unknown escape sequence `\%'".  Is there
>some command-line flag I can use or is this a bug?

Ok, well, gcc may give the warning, but the compiled program still will
give you the same response as cc, thought not very useful and not the same
across architectures.  What are you trying to do?  If you want to have the
string "%d" printed (with a newline), then you'd do:

	printf("%%d\n");

That is part of how printf() interprets the format string.

cc and gcc on both a Sun 3/280 running Sun Unix 4.2 R3.4 and an Encore
Multimax running UMAX 3.3 produce the equivalent result on each machine.
That is, on the Sun, both printed '0' and on the Multimax, both printed
-4664 (or something like that).  Of course, then the original printf has no
use (that I can see), if you did not want to print "%d".  Hope that helps...


                           -jeff

Jeff Kellem
INTERNET: composer@bu-cs.bu.edu   (or composer%bu-cs.bu.edu@bu-it.bu.edu)
UUCP: ...!harvard!bu-cs!composer

piet@cs.ruu.nl (Piet van Oostrum) (04/20/89)

In article <8904192118.AA09440@garnet.berkeley.edu>, rusty@GARNET writes:
 `The following program
 `
 `main() {
 `	printf("\%d\n");
 `}
 `
 `gets the complaint "warning: unknown escape sequence `\%'".  Is there
 `some command-line flag I can use or is this a bug?

Maybe you mean "\\%d\n" or "%%d\n" (depends on your desire to print also
the \).
-- 
Piet van Oostrum, Dept of Computer Science, University of Utrecht
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands
Telephone: +31-30-531806. piet@cs.ruu.nl (mcvax!hp4nl!ruuinf!piet)