I want a macro that declares an int with a given name and optional initializer expression.
I tried using this answer on Stack Overflow but with no success.
This is what I tried:
#define macro(...) int FIRST(__VA_ARGS__)(REST(__VA_ARGS__))
when used like this there are no problems:
macro(foo);
but when given an initializer there are errors:
macro(foo, 42);
The alternative - of just using __VA_ARGS__ gives a warning from -pedantic in GCC when there are no arguments.
How can I fix this?
And is it also possible to avoid the () braces when there is no initializer expression - meaning no zero initialization but default?
Note that my real use case is not just for int but for any type and using a third party like boost is not an option.