A89: Re: Re: ANSI C printf


[Prev][Next][Index][Thread]

A89: Re: Re: ANSI C printf




> I was in the midst of porting a program to the calc when I need
> the standard printf. There is a copy/paste on the doc page for 
> printf.h, but it does not compile at all... any solutions?

The example for "printf" works when you re-type it, but not when
you paste it. The problem is in the space. When you paste the
example, you will get

#define printf (format, args...) etc. etc.

But you must have:

#define printf(format, args...) etc. etc.

The difference is big: first variant means: define "printf"
without arguments which expands to "(format, args...) etc. etc.".
The second variant means: define "printf" with arguments 
"(format, args...)" which expands to "etc. etc.".

> You're right, the example code doesn't work. Change it to this:
>
> #define printf(format, args...) \
> {char buffer[200]; sprintf (buffer, format, ##args); puts (buffer);}
>
> I don't remember exactly what it is about the code that doesn't 
> work, but this variant does.

I hope that my explanation solves the "mystery".

Zeljko Juric