Date: Wed, 16 Jun 1999 23:23:53 +0200 From: Hans-Bernhard Broeker Message-Id: <199906162123.XAA01508@acp3bf.physik.rwth-aachen.de> To: djgpp AT delorie DOT com Subject: Re: #define and lines Newsgroups: comp.os.msdos.djgpp Organization: RWTH Aachen, III. physikalisches Institut B X-Newsreader: TIN [version 1.2 PL2] Reply-To: djgpp AT delorie DOT com In article <3768057F DOT 55A3A47A AT americasm01 DOT nt DOT com> you wrote: > I am actually using the C preprocessor to process html files. Ah, so my private guess turns out to be correct: a lassical case of 'wrong tool for the task'. Spoken figuratively, you're using a chainsaw to hammer in nails, and now you come to us and complain that the chainsaw doesn't get them in as straight as you want them. Seriously: CPP is really not meant to be used for anything but preprocessing C. For more general macro processing, other tools exist, like m4, sed, awk or perl. > The only problem > is the code is hard to read (if that is a problem, and I'm not convinced > either way). Well, you could always just block-format the resulting text, probably. There probably are other tools that do automatic pretty-formatting of HTML sources, as well, as 'indent' does for C. [...] > > With the preprocessor > > itself being a one-pass operation, you cannot generate preprocessor > > commands by macro-expansion, [...] > That's not entirely true. You can use -DMAC=#define on a > command-line to make a macro that expands to a preprocessor > directive. No. With a standard-conforming compiler and preprocessor, you can't. Or, more precisely: you can generate the string, but it won't become a preprocessor command. I've checked this (with gcc on a Linux box), just be sure I didn't misread K&R2 (in the middle of section A.12.3) on this issue. In the words of the C9x draft standard: [#5] The preprocessing tokens within a preprocessing directive are not subject to macro expansion unless otherwise stated. [#6] EXAMPLE In: #define EMPTY EMPTY # include the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced. (the 'otherwise stated' exception refers to the arguments of #if and #include, roughly). The trick is that you cannot generate a preprocessor command by macro expansion, ever. You can only generate text that *looks* like one, but it occurs too late, and therefore won't be interpreted as such. Which, as a side note, is the main reason why the FSF strongly oppose to the use of the #pragma directive, for anything: you can neither remove it from nor insert it into an existing source code, without the help of external text-processing tools. As to using '-Dmacro': that's 100% equivalent to adding a line '#define macro' at the very start of the source text. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.