macrosm4

What is the point of quoting the argument of the macro?


Reading the docs of the m4 macro language I have found that example:

changequote([,])dnl
define([gl_STRING_MODULE_INDICATOR],
  [dnl comment
  GNULIB_[]translit([[$1]], [a-z], [A-Z])=1dnl
])dnl
  gl_STRING_MODULE_INDICATOR([strcase])

which produces:

  GNULIB_STRCASE=1

But if one omits to quote strcase we have the same result:

  gl_STRING_MODULE_INDICATOR(strcase)

produces

  GNULIB_STRCASE=1

Why quoting strcase?


Solution

  • The quotes are required in case strcase is defined as a macro. For example, if we have define(strcase, foo), then gl_STRING_MODULE_INDICATOR(strcase) will expand first into gl_STRING_MODULE_INDICATOR(foo) and then into GNULIB_FOO=1.

    In general, well-written m4 input will continue to function when certain words unexpectedly happen to be defined as macros.