Skip to content

Instantly share code, notes, and snippets.

@Javran
Created January 9, 2013 08:57
Show Gist options
  • Save Javran/4491685 to your computer and use it in GitHub Desktop.
Save Javran/4491685 to your computer and use it in GitHub Desktop.
call functions that share one argument without indicating what the argument is repeatedly.
#include <cstdio>
void print3arg(int a, int b, int c)
{
printf("a=%d, b=%d, c=%d\n", a, b, c);
}
void print2arg(int a, int b)
{
printf("A=%d, B=%d\n", a, b);
}
int main()
{
#define _EXEC(FUNC, ...) FUNC(arg, __VA_ARGS__)
int arg = 1;
_EXEC(print3arg, 2, 3);
_EXEC(print2arg, 4);
{
int arg = 2;
_EXEC(print3arg, 2, 3);
_EXEC(print2arg, 4);
}
_EXEC(print2arg, 4);
#undef _EXEC
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment