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
- Uses function-like macros for library-style interfaces, compile-time checks, tracing, and interfaces that ordinary functions cannot express as directly.
- How deep it goes
- Explains textual replacement, evaluation and syntax hazards, argument checking, and invocation context, with an inline-function alternative.
- Examples
- Uses putchar replacement, a square macro with a side-effecting argument, a statement wrapper, and string-literal checking.
- What you can do after
- Evaluate function-like macros for repeated evaluation and syntactic hazards, and choose an inline function when appropriate.
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 macros to complement C interfaces when ordinary functions cannot express the needed behavior.
- How deep it goes
- Explains argument parsing, substitution and rescanning, then applies macro design rules to side effects and argument checking.
- Examples
- Works through putchar, a precedence-sensitive sum, a repeated-evaluation maximum and a string-literal check.
- What you can do after
- Apply it to design macro interfaces, identify expansion hazards and choose an inline function when appropriate.
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 →
What to know first
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- macroA macro is a named, reusable construct that expands into generated code or a sequence of commands when invoked, often during preprocessing, compilation, or application execution.
- _Generic_Generic is a C11 primary expression that selects one expression from type-associated alternatives according to the type of a controlling expression.
Related concepts
- procedural macrokind of · A procedural macro is Rust code that transforms an input token stream into generated code during compilation.
- macrokind of · A macro is a named, reusable construct that expands into generated code or a sequence of commands when invoked, often during preprocessing, compilation, or application execution.
- callequivalent to · A call is an invocation that requests execution of a function, routine, command, or tool, optionally supplying arguments.
- functionalternative to · A function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- inline functionalternative to · 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.
- macro invocationused by · A macro invocation is source syntax that requests expansion of a macro, typically with an associated name and arguments.
Questions about function-like macro
What is 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.
Which Manning books explain function-like macro?
Modern C, Third Edition, Modern C and Write Powerful Rust Macros.
What should I know before learning function-like macro?
Manning books that teach function-like macro usually introduce function, macro, comma operator and _Generic first.
What is the difference between function-like macro and function?
A function-like macro is a macro invoked with function-like syntax that accepts token input and expands or transforms it into generated source. A function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
What is function-like macro a kind of?
Function-like macro is a kind of procedural macro. A procedural macro is Rust code that transforms an input token stream into generated code during compilation.
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.


