Go to the first, previous, next, last section, table of contents.

Miscellaneous builtin macros

This chapter describes various builtins, that do not really belong in any of the previous chapters.

Printing error messages

You can print error messages using errprint:

errprint(message, ...)

which simply prints message and the rest of the arguments on the standard error output.

The expansion of errprint is void.

errprint(`Illegal arguments to forloop
error-->Illegal arguments to forloop

A trailing newline is not printed automatically, so it must be supplied as part of the argument, as in the example. (BSD flavored m4's do append a trailing newline on each errprint call).

To make it possible to specify the location of the error, two utility builtins exist:


which expands to the quoted name of the current input file, and the current input line number in that file.

errprint(`m4:'__file__:__line__: `Input error
error-->m4:in:1: Input error

Exiting from m4

If you need to exit from m4 before the entire input has been read, you can use m4exit:

m4exit(opt code)

which causes m4 to exit, with exit code code. If code is left out, the exit code is zero.

define(`fatal_error', `errprint(`m4: '__file__: __line__`: fatal error: $*
fatal_error(`This is a BAD one, buster')
error-->m4: in: 3: fatal error: This is a BAD one, buster

After this macro call, m4 will exit with exit code 1. This macro is only intended for error exits, since the normal exit procedures are not followed, e.g., diverted text is not undiverted, and saved text (see section Saving input) is not reread.

Turning sync lines on and off within m4

If you need to toggle sync lines on and off while processing macros, or to insure that they are off or on, you may do so using syncoutput.

syncoutput(1), syncoutput(on), and syncoutput(yes) causes m4 to emit sync lines of the form: #line <number> ["<filename>"].

syncoutput(0), syncoutput(off), and syncoutput(no) turn them off.

All other arguments are ignored as is syncoutput without parenthesis.

Go to the first, previous, next, last section, table of contents.