Next: , Previous: Inhibiting Invocation, Up: Macros


3.3 Macro arguments

When a name is seen, and it has a macro definition, it will be expanded as a macro.

If the name is followed by an opening parenthesis, the arguments will be collected before the macro is called. If too few arguments are supplied, the missing arguments are taken to be the empty string. However, some builtins are documented to behave differently for a missing optional argument than for an explicit empty string. If there are too many arguments, the excess arguments are ignored. Unquoted leading whitespace is stripped off all arguments.

Normally m4 will issue warnings if a builtin macro is called with an inappropriate number of arguments, but it can be suppressed with the --quiet command line option (or --silent, or -Q, see Invoking m4). For user defined macros, there is no check of the number of arguments given.

Macros are expanded normally during argument collection, and whatever commas, quotes and parentheses that might show up in the resulting expanded text will serve to define the arguments as well. Thus, if foo expands to `, b, c', the macro call

     bar(a foo, d)

is a macro call with four arguments, which are `a ', `b', `c' and `d'. To understand why the first argument contains whitespace, remember that leading unquoted whitespace is never part of an argument, but trailing whitespace always is.

It is possible for a macro's definition to change during argument collection, in which case the expansion uses the definition that was in effect at the time the opening `(' was seen.

     define(`f', `1')
     =>
     f(define(`f', `2'))
     =>1
     f
     =>2

It is an error if the end of file occurs while collecting arguments.

     define(
     ^D
     error-->m4:stdin:1: ERROR: end of file in argument list