Functional Macros in C
A function-like macro (also called a parameterised macro) accepts arguments and expands them inline — like a function, but done at the preprocessor stage before compilation. They are faster than function calls because there is no function call overhead.Syntax
Examples
Square of a number:Complete Program
Why Parentheses Matter
Without parentheses around parameters, expressions involving operators can produce wrong results:Macros vs Functions
| Functional Macro | Function | |
|---|---|---|
| Processed by | Preprocessor | Compiler |
| Type checking | None | Yes |
| Speed | Faster — inlined | Slight call overhead |
| Debugging | Harder | Easier |
| Code size | Larger | Smaller |
| Side effects | Possible | None |
inline functions in C99+ for type safety.