lundi 2 août 2021

How to convert a C-type variadic to C++ style variadic type?

I have a function which currently looks like this:

void log(uint8_t level, const char* fmt, ...) {
    va_list va;
    va_start(va, fmt);
    char msg[128];
    int  msg_size = vsnprintf(msg, 128, fmt, va);
    va_end(va);
    callback->dosomething(level, msg); // some api
}

I want to convert it to,

void log(uint8_t level, const char* fmt, Args... args) {
        va_list va;
        va_start(va, fmt);
        char msg[128];
        int  msg_size = vsnprintf(msg, 128, fmt, va); // do some things similar here with args
        va_end(va);
        callback->dosomething(level, msg); // some api
    }

Can someone help me with that?

Aucun commentaire:

Enregistrer un commentaire