This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patch to add __builtin_printf


On Wed, 20 Sep 2000, Zack Weinberg wrote:

> Hm... Appears to me you're working too hard.  You know you are using GCC's
> preprocessor, therefore you can inject
> 
> #undef printf
> #define printf(args...) fprintf(stdout, args...)

It seems that the general agreement at this time is NOT to do this with
the help of preprocessor, but allow me to list some of the perhaps not so
obvious reasons why you wouldn't want to do that.

Assuming "printf" macro defined as above:


1.

#define OPEN_BRACE (
#define CLOSE_BRACE )

void f(void)
{
        printf OPEN_BRACE "Hello, world!\n" CLOSE_BRACE;
}

This results after preprocessing in:

	printf (  "Hello, world!\n" ) ;

(OK, not exactly catastrophic, but still not what was intended :-)


2.

void g(void)
{
        printf(
#ifdef SOMETHING
                        "Something"
#else
                        "Something else"
#endif
                        );
}

Now, this gives:

p.c:20: warning: preprocessing directive not recognized within macro arg
p.c:20: warning: preprocessing directive not recognized within macro arg
p.c:20: warning: preprocessing directive not recognized within macro arg

(at least with 2.95.2, I don't know how it behaves with the new
preprocessor)


3.

class h
{
        void printf();
};

This gives:

class h
{
        void fprintf(stdout,   ...) ;
};

Not very likely to be accepted, eh?


To sum it up:

NEVER do that for something as broadly used as stdio's printf.

-- 
/ Kamil Iskra  kamil@wins.uva.nl                                          \
| Section Computational Science, Faculty FNWI, Universiteit van Amsterdam |
| tel. +31 20 525 75 35  fax. +31 20 525 74 90                            |
\ Kruislaan 403  room F.202  1098 SJ Amsterdam (NL)                       /


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]