C/C++ call a variadic function

  ansi-c, c++, variadic

I write a command interpreter that parses a command and its arguments and I would like to find a way to pass them to various non-variadic functions like this:

typedef boolean (*CommandExecuteCallback)(char* arg1, ...);  // n argument variadic function

char command[CMD_WORD_MAXLEN+1];  // currently parsed command
char args[CMD_MAX_ARGUMENTS][CMD_WORD_MAXLEN+1];     // currently parsed arguments

const char *commands[CMD_MAX_COMMANDS];             // available commands
CommandExecuteCallback commandf[CMD_MAX_COMMANDS];  // available execution functions

executeCommand(char *buf)
{
    // find command and parse args
    // call it
    commandf[i](this->args);
}

bool cmd_blink(char* onOff) { ... }
bool cmd_something(char* arg1, char* arg2) { ... }

I am not sure this is possible in C/C++ and definitely not documented here:
https://en.cppreference.com/w/cpp/utility/variadic

Source: Windows Questions C++

LEAVE A COMMENT