[Coco] glork!!!

Alex Evans alxevans at concentric.net
Wed Dec 19 13:27:19 EST 2007


On  17  Dec 2007, at 6:39 AM, Gene Heskett wrote:

> On Monday 17 December 2007, Willard Goosey wrote:
>> Anybody ever notice that the Kreider C lib "printf" returns really
>> strange values?
>
> Its always worked for me.
>
>> Yes, I know I can't expect ANSI compliance (which is to return the
>> number of charaters printed) but "return 0 on sucess, -1 on failure"
>> IS proper K&R behavior.
>>
>> I was throwing together a quick yes(1) to help with using deldir in a
>> shell script, and was about to post it here, when I thought, "I'd
>> better try it under OS-9 just to make sure it works...."
>>
>> The sad thing is, I'd written a yes(1) long ago, I think it's on  
>> rtsi,
>> and it works.... because the printf() just *happens* to return a
>> positive number the way it was called.
>>
>> Specifically, ..printf("foo bar\n") returned -79xxx and
>> ... printf("%s\n","foo bar") returns 31744!
>>
>> Very very strange.
>>
>> Willard
>
> You are leaving out the output format specifier in the first case  
> Willard.  Go
> look up printf in any C reference book.  Also, the "foo bar" should  
> point at
> the defined variables.  Either that or bit rot has gotten to your  
> copy...
>
> Normal syntax would be:
>
> printf("list-of-format-strings\r", nameofvar, nameofvar, etc);
>
> That's off the top of my head, but that's how I remember it, having  
> written a
> bunch of stuff in C.

Actually Willard's syntax is correct.  It just happens that in the  
first case the format specifier contains no fields for variables and  
has an empty variable list.  In addition, since C uses pass by value,  
the second is also perfectly legal.
The reason for the odd values is probably that printf is being given  
no return value at all.



More information about the Coco mailing list