I would like to make a macro F
taking a variable number of parameters, that expands to the parameters each separated by a ||
. e.g. F(a, b, c)
should expand to a || b || c
, F(a)
should expand to just a
, etc.
I know C doesn't support recursive macros. I only need this for at most 4 arguments currently.
I was thinking something like #define F(a, ...) a || F(__VA_ARGS__)
, and then a second macro to get that to expand 4 times, but I'm not sure at all what that other macro should look like. And I run into the issue of having an empty __VA_ARGS__
at some point. Any other ideas would be much appreciated.
Restrictions: must work with any standard-conforming C99 compiler.
EDIT: I've got this working using Overloading Macro on Number of Arguments, but still curious if there's another solution.