Re: Complete macro expansion with cpp

"Skandinavisches Seminar" <skandgoe@gwdg.de>
13 Feb 2005 22:46:32 -0500

          From comp.compilers

Related articles
Complete macro expansion with cpp peter.mathes@gmx.de (2005-02-12)
Re: Complete macro expansion with cpp RLake@oxfam.org.uk (Rici Lake) (2005-02-13)
Re: Complete macro expansion with cpp skandgoe@gwdg.de (Skandinavisches Seminar) (2005-02-13)
Re: Complete macro expansion with cpp codeworker@free.fr (2005-02-16)
Re: Complete macro expansion with cpp codeworker@free.fr (2005-02-16)
Re: Complete macro expansion with cpp peter.mathes@gmx.de (peter.mathes@gmx.de) (2005-02-16)
| List of all articles for this month |
From: "Skandinavisches Seminar" <skandgoe@gwdg.de>
Newsgroups: comp.compilers
Date: 13 Feb 2005 22:46:32 -0500
Organization: GWDG, Goettingen
References: 05-02-059
Keywords: C, macros
Posted-Date: 13 Feb 2005 22:46:32 EST

<peter.mathes@gmx.de> schrieb im Newsbeitrag


> I need to get all macro #definitions output to stdout or some file.
> The problem is: [...]


One easy way to do what you want would be to use Don Knuth and Silvio
Levy's CWEB. You could put your definitions in a section, say,
`@<Macro definitions@>', and include this section in a section that's
written to a file, e.g.:


@(macros.c@>'=
  `@<Macro definitions@>'


Then run `ctangle' on your source file and cpp on `macros.c'. The
latter will contain only your macro definitions. You will have to
include `@<Macro definitions@>' in another section in your source
file, too, in order to be able to use the macros in your code.


However, I'd be interested to know why you want to do this in the
first place. I generally try to avoid using macros except for things
that I can't do any other way, such as conditional compilation and
including header files. In _The Design and Evolution of C++_, Bjarne
Stroustrup goes into detail about his objections to CPP, and I believe
that his arguments are all cogent. In particular, I believe they
apply to C as well as C++.


While I have tried to answer your question, I believe that doing this
would not be making the best use of C. One important objection
Stroustrup raises is that macro constructions (I prefer the term
"macro trickery") evade the control of the compiler, making them
difficult to debug.


Laurence Finston
http://www.gnu.org/software/3dldf/LDF.html
lfinsto1@gwdg.de


Post a followup to this message

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