Macros programming relies on extensions such as Typeof, auto, and Statement Expressions.
There are still a couple of problems
-
Multi-line macros are annoying
-
Collision of variable names
#define foo(x) \
({ \
__auto_type a = (x); \
})
int main()
{
int a = 1;
foo(a);
}
- Semicolons can not appear as part of arguments
#define min(x, y) \
({ __auto_type _x = (x); \
__auto_type _y = (y); \
(_x < _y) ? _x : _y; \
})
-
No pattern matching of expression
-
Compound expressions can not be used safely in macros because curly brackets are not parsed:
foo((int[]){ 0, 0 })
- Compound expressions can not be used safely inside Statement Expressions
Life time of a compound expressions used in a macro written using a statement expression ends, so can not be returned.
New kind of macros?
#macro foo(x * y)
mul(x, y)
#endmacro