This is the mail archive of the gcc@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: Gcc 3.0, printf() and exim-3.30


On Wed, Jun 20, 2001 at 11:45:18PM +0100, Nix wrote:
> 
> >> gcc -c -DNOPOSIX -O  pcretest.c
> >> pcretest.c:474:1: directives may not be used inside a macro argument
> 
> Correct, but not relevant to this situation, I think.

On the contrary.

> > The code in question reads:
> > 
> >       printf("  -d   debug: show compiled code; implies -i\n"
> >              "  -i   show information about compiled pattern\n"
> >   #if !defined NOPOSIX
> >              "  -p   use POSIX interface\n"
> >   #endif
> >              "  -s   output store information\n"
> >              "  -t   time compilation and execution\n");
> > 
> > It looks as if gcc 3.0 has printf defined as a macro. IMHO this is
> > lunacy.
> 
> Nope; printf is not a macro, and GCC does not define printf :)

But GNU libc does, when used with GCC in optimizing mode.  The C
standard permits the library to define any standard function as a
macro, provided that there is a real function as well.

The C standard also says

	If there are sequences of preprocessing tokens within the list
	of arguments that would otherwise act as preprocessing
	directives, the behavior is undefined.

(C99 6.10.3 paragraph 11).  This is just the case you have tripped
over.  The error message means exactly what it says - you cannot use
any directive in text which is read as the arguments of a macro.

You can #undef printf immediately after #include <stdio.h>, or write

	(printf)(" -d ..."
		 ...
		);

which will suppress macro expansion for that use only.  There doesn't
seem to be a way to prevent glibc from defining all its stupid macros.
You should report that as a bug to the glibc maintainers.

> I think your #if itself is triggering a bug in GCC; a workaround may be
> to say
> 
> #if !defined(NOPOSIX)

I don't think that has anything to do with it.

> The error you're getting is meant to be triggered by code like
> 
> #if #else
> 
> which is obvious nonsense; but it doesn't seem to me that this should be
> triggered here.

#if #else is actually acceptable to GCC, it counts as a use of the
deprecated "assertions" extension.  Other such obvious nonsense, e.g.
#else #endif, will get you "warning: extra tokens at end of #whichever
directive".

-- 
zw     I was putting away groceries in our kitchen when I got to the
       cabbages and thought "this needs to be tossed into air, preferably
       without looking up first."
       	-- James Nicoll


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