Re: C preprocessor vs Macro processor

Greg Badros <gjb@cs.washington.edu>
7 Nov 1997 00:47:43 -0500

          From comp.compilers

Related articles
C preprocessor vs Macro processor peter.govoni@analog.com (Peter Govoni) (1997-11-02)
Re: C preprocessor vs Macro processor gjb@cs.washington.edu (Greg Badros) (1997-11-07)
Re: C preprocessor vs Macro processor tgm@netcom.com (1997-11-11)
Re: C preprocessor vs Macro processor ok@cs.rmit.edu.au (1997-11-13)
| List of all articles for this month |

From: Greg Badros <gjb@cs.washington.edu>
Newsgroups: comp.compilers
Date: 7 Nov 1997 00:47:43 -0500
Organization: Computer Science, U of Washington, Seattle, WA, USA
References: 97-11-021
Keywords: macros

Peter Govoni <peter.govoni@analog.com> writes:


> Could someone please explain why a macro processor (e.g. M4)
> is 1) more powerful than the C preprocessor and


M4 allows rearranging code too. e.g., you can have a macro that takes
part of its arguments and writes them out to a diverted channel, and
then later output that previously-hidden channel. Cpp allows only
local expansion of macros.


Also, M4 has many many more builtin functions (including regular
expression matching, and much more) and permits recursive macros; Ansi
C's cpp disallows recursion in macros.


M4 also permits a macro's expansion to include a newline; cpp cannot
(hence the imake hack of replacing @@ w/ newlines after the
preprocessor has run).


> 2) more suitable for assembly languages


Perhaps because M4 is more powerful; you can build more infrastructure
more easily w/ M4, raising the level of abstraction more easily --
something assembly truly benefits from.


> Does the C preprocessor hold any advantage over M4 ?


It's easier to learn, is not stuck with complicated quoting rules, and
more constrained in its capabilities; reasoning about source code
preprocessed by cpp is hard enough -- reasoning about source code
processed by m4 would be nearly impossible.


Greg J. Badros
gjb@cs.washington.edu
Seattle, WA USA
http://www.cs.washington.edu/homes/gjb




--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.