#define kinda stuff

richw at ada-uts richw at ada-uts
Wed Apr 16 00:24:00 AEST 1986


I don't have any suggestions, but I might be able to provide some
insight...

I think it depends on your implentation of C.  You see, it depends
on what the "lexical analyzer" of your particular compiler does to
the text in the C-preprocessor lines.  It would seem that when you
say:

    #define foo <text here>

that this has the same effect as doing a global replace, as editors
do, of "foo" with "<text here>".  However, at least some compilers
I know of first cut up "<text here>" into lexical tokens, i.e. it
breaks up the text into identifiers, strings, special C symbols
(like '{' and '}'), and so on.  This sequence of TOKENS, (not simply
the sequence of characters) is then used wherever "foo" is encountered
(this is actually more efficient since lexical analysis of "<text here>"
is then only performed once for each occurence of "foo").

The important point, though, is that most lexical analyzers throw
away comments.  So, if your compiler does this, I see little hope of
EVER being able to re-define C's comment delimiters.  Judging by your
description of the various things you tried, it seems as if your
compiler does indeed lex the text of a define, so if I were you
I'd give up and REALLY start hacking with "sed" or something.

By the way, you'd think that what C is supposed to do here is well-
defined.  Well, unless the standard that ANSI's working on does so,
I know of no such clear definition.  A while ago, I played with the
idea of writing a lexer for C and discovered that there were some
ambiguities (within Kernighan & Ritchie, at least) as to what
#define REALLY means.

You might want to check Harbison & Steele; that C text might make
mention of this sort of thing (I, unfortunately, don't own a copy,
but I've looked at it and it's usually more specific than K&R about
most things).

Hope this helped,
Rich Wagner



More information about the Comp.lang.c mailing list