liveBook · Manning

Macro argument

As explained in Modern C

A macro argument is a preprocessing token sequence supplied in a function-like macro call and substituted for a corresponding macro parameter.

A macro argument is the preprocessing-token sequence supplied for a parameter in a function-like macro call. In BYTECOPY(A, B), A and B are separated by the comma outside any nested parentheses. section 16.1

Preprocessing handles macro arguments in a defined sequence:

  • Scans parentheses and commas; nested parentheses keep commas inside one argument. section 16.1
  • Requires the argument count to match the macro’s parameter count. section 16.1
  • Recursively expands macros appearing inside each argument before substitution. section 16.1
  • Substitutes the resulting fragments into copied replacement text, which is then expanded again. section 16.1

Nested argument expansion

Given BYTECOPY(A, B), if A expands to redA, preprocessing can produce memcpy(&(redA), &(B), ...). The argument A is expanded before it replaces the corresponding parameter. section 16.1

How Modern C covers it

How deep it goes
Traces parsing, recursive expansion, substitution, and reinsertion, but stops short of broader macro features.
Examples
Uses BYTECOPY(A, B), nested parentheses and commas, and an A-to-redA expansion to illustrate argument handling.
What you can do after
Evaluate macro calls by tracing argument boundaries, nested expansion, parameter substitution, and final replacement text.
How it connects
Connects macro arguments with preprocessing, function-like macros, macro parameters, replacement text, and recursive macro expansion.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.