This is the mail archive of the egcs@egcs.cygnus.com mailing list for the EGCS project. See the EGCS home page for more information.


[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

Problem with the EGCS cpp?



The egcs cpp seems to be causing problems with macro expansion.
A project I am working on has a macro

#define SCOPE(arg) arg

which is defined if namespaces are supported and

#define SCOPE(arg)

otherwise. The intent is for

#ifdef HAVE_NAMESPACES
namespace foo {
#endif

int bar;

#ifdef HAVE_NAMESPACES
}
#endif


...

SCOPE(foo)::bar = 3;

to expand with

::bar = 3;

without namespaces and

foo::bar = 3;

with them. So the same code works on older gcc and egcs without namespaces
and on newer egcs, and on the latter makes use of namespaces.

The problem is that the cpp in the egcs 1.1.1 release is producing stuff like

foo   ::bar = 3;

with extra spaces. I double and triple checked that there is no whitespace
on the end of the line defining the macro; a newline immediately follows
"arg". So the preprocessor seems to be creating extra whitespace out of
thin air and this is causing a parse error in the macro testing code.

Question #1: Is this documented behavior of cpp?
Question #2: Is it supposed to do this?
Question #3: If so, how do I suppress this extra whitespace?
Question #4: If it's a bug, is there a known workaround?

I checked the cpp info file. It makes no mention of generating whitespace
when expanding macros, nor does it mention anything about suppressing
whitespace.

The course of action I would most prefer would be to just lose the macros
altogether and use namespaces normally, but I would rather avoid that
unless I can be sure namespaces will be widely supported by stable stock
gcc and egcs and possibly other compilers by the time the project is
complete and ready for deployment.

-- 
   .*.  "Clouds are not spheres, mountains are not cones, coastlines are not
-()  <  circles, and bark is not smooth, nor does lightning travel in a
   `*'  straight line."    -------------------------------------------------
        -- B. Mandelbrot  |http://surf.to/pgd.net
_____________________ ____|________     Paul Derbyshire     pderbysh@usa.net
Programmer & Humanist|ICQ: 10423848|