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: cpplib: get -traditional correct outside directives




Zack Weinberg wrote:
> 
> On Mon, May 15, 2000 at 07:45:36PM +0900, Neil Booth wrote:
> > This patch gets -traditional correct outside directives, by continuing
> > to parse identifiers or numbers interrupted by a comment.
> >
> > e.g. 1.2/**/e-4  is tokenized as <1.2e-4>
> >      1.2 /**/e-4 is tokenized as <1.2> < e> <-> <4>
> >      foo/**/bar is tokenized as <foobar>
> >
> > and thus if foobar is a macro it will be expanded normally.

In open text foo/**/bar should be seen by the compiler as the
identifier foobar, but foobar should not expand if it's a macro.

If foo/**/bar appears in the replacement of another macro which
is expanded, *then* foobar also get expanded.

To understand the difference, always go back to how the
preprocessor/compiler interacted *textually* in a traditional K&R
compiler:

The preprocessor scanned text looking for macro names to replace
and removing comments. In open text, given foo/**/bar, it sees
the identifier foo, removes the comment and then sees the
identifier bar. There is no rescanning by the preprocessor,
however the outout -- foobar -- is seen as a single identifier by
the compiler.

Given

#define foobar 1
#define ACK foo/**/bar
ACK

The preprocessor scans the #define an sees the identifier foo,
removes the comment and sees the identifier bar. ACK is defined
as the *text* foobar. When ACK is expanded, it is replaced with
foobar which gets rescanned and recognized as a macro which is
then, in turn expanded.

If you think of the traditional preprocessor as removing
comments, replacing macro invocations with *text* that gets
rescanned and outputting *text* which gets rescanned by the
compiler, you will always arrive at the correct behaviour.

Dave

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