The examples below use the following macros:
define([car], [$1]) define([active], [ACT, IVE]) define([array], [int tab])
Each additional embedded macro call introduces other possible interesting quotations:
car(active) ⇒ACT car([active]) ⇒ACT, IVE car([[active]]) ⇒active
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:
car(ACT, IVE) ⇒ACT
In the second case, the top level gives ‘active’ as first and only
car, which results in:
active ⇒ACT, IVE
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:
car(int tab;) ⇒int tab10; car([int tab;]) ⇒int tab10; car([[int tab;]]) ⇒int tab;
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:
qar([int tab;]) ⇒int tab;
Ahhh! That's much better.
But note what you've done: now that the result of
qar is always
a literal string, the only time a user can use nested macros is if she
relies on an unquoted macro call:
qar(active) ⇒ACT qar([active]) ⇒active
leaving no way for her to reproduce what she used to do with
car([active]) ⇒ACT, IVE
Worse yet: she wants to use a macro that produces a set of
define([my_includes], [#include <stdio.h>]) car([my_includes]) ⇒#include <stdio.h> qar(my_includes) 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.