Прочитав о VA_NARG
, я попытался реализовать перегрузку функций в зависимости от количества аргументов в C с помощью макросов. Теперь проблема:
void hello1(char *s) { ... }
void hello2(char *s, char *t) { ... }
// PP_NARG(...) macro returns number of arguments :ref to link above
// does not work
#define hello(...) hello ## PP_NARG(__VA_ARGS__)
int main(void)
{
hello("hi"); // call hello1("hi");
hello("foo","bar"); // call hello2("foo","bar");
return 0;
}
Я прочитал это из C-faq. Но все никак не мог заставить его работать ...