Function-like macro
A function-like macro is a macro invoked with function-like syntax that accepts token input and expands or transforms it into generated source.
Modern C, Third Edition
A function-like macro is a C preprocessor macro invoked with parentheses and arguments that expands its invocation into replacement source text.
- How it is used
- Positions function-like macros as substitutes for some library interfaces and as tools for checks, tracing, and interfaces functions cannot readily express.
- How deep it goes
- Works through textual replacement, repeated evaluation, statement-shape pitfalls, compile-time checks, and invocation-site tracing.
- Examples
- Contrasts `square_macro(count())` with an inline function, repairs a dangling `else`, and checks a string-literal argument.
- What you can do after
- Build it from scratch for checks or tracing while recognizing when an inline function avoids duplicated evaluation and provides a typed interface.
Read how Modern C, Third Edition explains function-like macro →
Modern C
A function-like macro is a C macro defined with parameters that expands preprocessing tokens when invoked with an argument list resembling a function call.
- How it is used
- Uses call-shaped preprocessing replacements where functions cannot supply argument checks, defaults, variable argument lists, or type-generic interfaces.
- How deep it goes
- Works through argument separation, expansion, substitution, and rescanning, then examines evaluation and syntax hazards.
- Examples
- Contrasts a squaring macro with an inline function and uses a dangling-else repair and string-literal checking to expose practical constraints.
- What you can do after
- Build it from scratch when needed, while choosing inline functions for ordinary typed calls and checking expansion for duplicated effects or surprising syntax.
Write Powerful Rust Macros
A function-like macro is a Rust procedural macro invoked with the ! operator that accepts arbitrary token input and replaces that input with generated output.
- How it is used
- Generates replacement Rust from flexible token input for transformations and mini-DSLs beyond annotated items.
- How deep it goes
- Works through macro signatures, token parsing, custom parsers, quoted output, block scoping, and compiler-guided debugging.
- Examples
- Uses a struct-accessor macro, dot-separated function composition, YAML configuration generation, and implementation exercises.
- What you can do after
- Build it from scratch by parsing token input, generating replacement code, and selecting a narrower macro when possible.
Read how Write Powerful Rust Macros explains function-like macro →
Related concepts
- procedural macrokind of · A procedural macro is a Rust macro implemented as a program that transforms an input token stream into generated code during compilation.
- macrokind of · A macro is a named construct that expands or transforms source code, commands, or templates before or during execution.
- functionalternative to · A function is a callable program unit that performs an operation, may accept inputs, and can produce a result or side effect.
- callequivalent to · A function call is an operation or expression that invokes a function or other callable, optionally supplies arguments, and initiates its execution.
- inline functioncontrasts with · An inline function is a function defined or designated for incorporation at its use site, either syntactically or through compiler substitution, rather than necessarily invoked through an ordinary call.
- variadic macroincludes · A variadic macro is a function-like C preprocessor macro whose parameter list accepts a variable number of arguments through an ellipsis.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


