Last active
February 19, 2017 21:19
-
-
Save xsnpdngv/5dbac4d757c2b080ec8c53d8107b0fa7 to your computer and use it in GitHub Desktop.
C function-like macro overload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* overload for function-like macros with various number of named arguments */ | |
#define OVERLOAD(Func, .../* Arg1[, Arg2[, Arg3]] */) \ | |
FUNC_SEL(__VA_ARGS__, Func##3, Func##2, Func##1, x)(__VA_ARGS__) | |
#define FUNC_SEL(Arg1, Arg2, Arg3, Func, ...) Func | |
#define FUNC(/* arg1[, arg2[, arg3]] */ ...) OVERLOAD(FUNC, __VA_ARGS__) | |
#define FUNC2(arg1, arg2) arg1#arg2 /* whatever to do with 2 args */ | |
#define FUNC3(arg1, arg2, arg3) arg1#arg2#arg3 /* whatever to do with 3 args */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This way
FUNC()
can be called with 2 or 3 arguments and actuallyFUNC2()
orFUNC3()
will be expanded accordingly