| || |
Macros which can expand to different strings based on runtime tests are extremely useful--they are used extensively throughout macros in GNU Autotools and third party macros. The macro that we will examine closely is
The other form is unusual to a beginner because it actually resembles a
If `string1' and `string2' are equal, this macro expands to `equala' . If they are not equal,
If `string3' and `string4' are equal, this macro expands to `equalb' . If they are not equal, it expands to `default' . The number of cases that may be in the argument list is unbounded.
As it has been mentioned in 21.3.2 Macros and macro expansion, macros that accept arguments may access their arguments through specially named macros like `$1' . If a macro has been defined, no checking of argument counts is performed before it is expanded and the macro may examine the number of arguments given through the `$#' macro. This has a useful result: you may invoke a macro with too few (or too many) arguments and the macro will still be expanded. In the example below, `$2' will expand to the empty string.
This is useful because
In this example, we wish to accept the default shell code fragment for the case where `/etc/passwd' is found in the build system's file system, but output `Big trouble!' if it is not.