0

I have two functions, both taking variadic arguments. One function should call the other, with said arguments. The functions look like this:

void make_error(const char *line, unsigned int line_no, unsigned int char_no,
                unsigned int len, const char *error_message, ...)
    va_list l;
    va_start(l, error_message);
    message_internal("\033[31;1m", line, "error", line_no, char_no, len, error_message, l);
    va_end(l);
}
void throw(SubstringInformation* info, const char* format, ...) {
    va_list l;
    va_start(l, format);
    // this does not work, but doesn't produce an error or warning
    make_error(info->line_content, info->line_in_file, info->char_in_line,
               info->text_len, format, l);
    va_end(l);
}
Tenobaal
  • 637
  • 1
  • 16
  • 1
    Note: the linked duplicate is notionally about C++, but the accepted (and highest-scored) answer is actually C. Just ignore the C++-specific answers. – Useless Aug 16 '22 at 14:10
  • Thanks, I didn't find this one :) But does that mean there is no way to do this? – Tenobaal Aug 16 '22 at 14:25
  • Correct. Since you cannot know at compile time the number and types of arguments, the compiler cannot generate a call. – the busybee Aug 16 '22 at 14:28
  • In general if you need to _forward_ a variable number of arguments, your options are to make the inner function accept a `va_list` parameter (like [`vprintf`](https://en.cppreference.com/w/cpp/io/c/vfprintf) does), **or** to make the outer function a variadic template. – Useless Aug 16 '22 at 14:30

0 Answers0