8.1.3 Quotation and Nested Macros
The examples below use the following macros:
define([active], [ACT, IVE])
define([array], [int tab])
Each additional embedded macro call introduces other possible
In the first case, the top level looks for the arguments of
and finds ‘active’. Because M4 evaluates its arguments
before applying the macro, ‘active’ is expanded, which results in:
In the second case, the top level gives ‘active’ as first and only
car, which results in:
i.e., the argument is evaluated after the macro that invokes it.
In the third case,
car receives ‘[active]’, which results in:
exactly as we already saw above.
The example above, applied to a more realistic example, gives:
Huh? The first case is easily understood, but why is the second wrong,
and the third right? To understand that, you must know that after
M4 expands a macro, the resulting text is immediately subjected
to macro expansion and quote removal. This means that the quote removal
occurs twice—first before the argument is passed to the
macro, and second after the
car macro expands to the first
As the author of the Autoconf macro
car, you then consider it to
be incorrect that your users have to double-quote the arguments of
car, so you “fix” your macro. Let's call it
and check that
qar is properly fixed:
Ahhh! That's much better.
But note what you've done: now that the arguments are literal strings,
if the user wants to use the results of expansions as arguments, she has
to use an unquoted macro call:
where she wanted to reproduce what she used to do with
Worse yet: she wants to use a macro that produces a set of
define([my_includes], [#include <stdio.h>])
error-->EOF in argument list
qar, because it double quotes its arguments, forces
its users to leave their macro calls unquoted, which is dangerous.
Commas and other active symbols are interpreted by M4 before
they are given to the macro, often not in the way the users expect.
qar behaves differently from the other macros,
it's an exception that should be avoided in Autoconf.