public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* CPP preprocessor: #define-splitting?
@ 2004-08-26  6:46 Florian Stoehr
  2004-08-26  7:13 ` Eljay Love-Jensen
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Stoehr @ 2004-08-26  6:46 UTC (permalink / raw)
  To: gcc-help

Hi,

I'm developing a gcc-compatible preprocessor for a compiler project. While
doing this, I discovered something strange.

In preprocessor documentation:

    /\
     *
     */ # /*
     */ defi\
     ne FO\
     O 10\
     20


will expand to "#define FOO 1020". It does.

But:

# /*
*/ define TEST "foo"

--> #define TEST "foo"

Replacing the "#" by an "X" will produce with gcc -E:

X
 define TEST "foo"


_BUT_:
#
 define TEST "foo"

--> TEST doen't get defined.

The problem is: Why does it recognize the "#" and "define" splitted by a
multi-line comment as "#define"? Is this the correct behaviour?

Thanks for your help
Florian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: CPP preprocessor: #define-splitting?
  2004-08-26  6:46 CPP preprocessor: #define-splitting? Florian Stoehr
@ 2004-08-26  7:13 ` Eljay Love-Jensen
  2004-08-26 12:10   ` Florian Stoehr
  0 siblings, 1 reply; 3+ messages in thread
From: Eljay Love-Jensen @ 2004-08-26  7:13 UTC (permalink / raw)
  To: Florian Stoehr, gcc-help

Hi Florian,

The # is a preprocessor directive.

The X is not a preprocessor directive.

The rules for parsing preprocessor directives is different form the rules 
for parsing non-preprocessor directives.  (The state machine is in a 
different state.)

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: CPP preprocessor: #define-splitting?
  2004-08-26  7:13 ` Eljay Love-Jensen
@ 2004-08-26 12:10   ` Florian Stoehr
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Stoehr @ 2004-08-26 12:10 UTC (permalink / raw)
  To: Eljay Love-Jensen; +Cc: gcc-help

On Wed, 25 Aug 2004, Eljay Love-Jensen wrote:

> Hi Florian,
>
> The # is a preprocessor directive.
>
> The X is not a preprocessor directive.
>
> The rules for parsing preprocessor directives is different form the rules
> for parsing non-preprocessor directives.  (The state machine is in a
> different state.)
>
> HTH,
> --Eljay
>
>

Hi,

thanks for the reply. But there seems to happen something strange BEFORE
the preprocessing itself (in comment remove stage?).

Why am I allowed to do a...

# /*
*/ define

and a

#
 define

not? I thought the stage where it strips out comments comes before the
"main" preprocessor where it scans for #-directives. so why is the #
define allowed to be split on multiple lines WITHOUT a backslash-newline?

afaik, any comment gets replaced by a single " " and every newline inside
the comment gets added AFTER the comment.

so the

# /*
*/ define

should become a

#
 define

after the comment removing stage - but this does not work see above.

(just confused wheter it does something special with comments "inside" a
#-directive)

-Florian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-08-26  7:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-26  6:46 CPP preprocessor: #define-splitting? Florian Stoehr
2004-08-26  7:13 ` Eljay Love-Jensen
2004-08-26 12:10   ` Florian Stoehr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).