[Coco] glork!!!

Willard Goosey goosey at virgo.sdc.org
Tue Dec 18 05:22:35 EST 2007



>Date: Mon, 17 Dec 2007 11:39:01 -0500

>From: Gene Heskett <gene.heskett at verizon.net>



>Its always worked for me.


For me, too, until I started carefully checking its return value. ;-)


>>Specifically, ..printf("foo bar\n") returned -79xxx and

>>... printf("%s\n","foo bar") returns 31744!

>>

>You are leaving out the output format specifier in the first case

>Willard. Go look up printf in any C reference book.


K&R, page 6: ...printf("hello world\n");

Not that K&R ever actually specify printf's return value... Like many
things in K&R, it's just sort of assumed... The man page for
printf(3) on an AT&T K&R compiler says it returns the number of
characters printed.


>Also, the "foo bar" should point at the defined variables. Either

>that or bit rot has gotten to your copy...


Yeah, yeah, the compiler had to generate a thunk. That's what
compilers are for, and if it couldn't handle, the format-string
wouldn't work either.


>printf("list-of-format-strings\r", nameofvar, nameofvar, etc);


More formally: int printf(control [, arg1,] ...)
char *control;

(Again, from the AT&T man page.)


>That's off the top of my head, but that's how I remember it, having

>written a bunch of stuff in C.


Overly restrictive, but essentially correct.

You want scary? Read the C99 spec for the %n specifier! That is NOT
printf's job!

Willard
--
Willard Goosey goosey at sdc.org
Socorro, New Mexico, USA
"I've never been to Contempt! Isn't that somewhere in New Mexico?"
--- Yacko



More information about the Coco mailing list