tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: traditional cpp

> I also apparently don't have the right ideas about comment removal in
> traditional cpp, because it currently exhibits the behavior that

>    #define STOP */
>    #define START /*
>    /* hello there STOP fnord START ho hum */

> outputs "fnord", which cannot be what anyone intended.

That's an interesting corner case.

I'm not sure what I think the right thing is (but, I agree, that ain't
it), and I no longer have a real old-school cpp on hand to try, at
least not at ready hand.  (I may have a 4.4Lite CD or some such with
one.  I'm not sure.)

> How's it supposed to be done?  Right now it's removing comments after
> macro expansion, but if it removes comments before macro expansion
> then /**/ doesn't work for pasting...

Remove comments after macro expansion, yes.  If the /* on the START
definition begins a comment, it continues up through the end of the
next line; if not, then the next line is a comment, and macro expansion
never happens inside comments.

I wrote a preprocessor back in the '90s, mostly to relieve a few
annoying limitations such as the inability of a macro to expand to a
macro definition.  It treates @ kind of like # but able to appear
anywhere, and has (integer-valued) variables, looping constructs, and
the like. I didn't mention it because I thought we already had plenty
of preprocessors, but if anyone wants a copy, I'll be happy to send it
out or put it up for ftp.

For what it's worth, when fed those three lines (with no trailing
whitespace) my code produces a single newline as output.  (On
investigation, it turns out it defines START to be everything from the
/* up to the end of the next line - the macro definition includes the
entire comment, including the newline.)

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML      
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Home | Main Index | Thread Index | Old Index