------- Comment #20 from matz at gcc dot gnu dot org 2010-08-11 16:10 ------- A conforming variant of what you probably are trying to code is: -------------------------------------------------------------------- #include <stdio.h> #include <stdarg.h>
void format_indirect(char* dst_buffer, size_t dst_buffer_size_bytes, const char *format, va_list va) { vsnprintf(dst_buffer, dst_buffer_size_bytes, format, va); dst_buffer[dst_buffer_size_bytes-1]=0; } void format_direct(char* dst_buffer, size_t dst_buffer_size_bytes, const char* format, ...) { va_list va; va_start (va, format); format_indirect(dst_buffer, dst_buffer_size_bytes, format, va); va_end (va); } int main(void) { char buffer[1000]; format_direct((char*)buffer, sizeof(buffer), "%s %s", __DATE__, __TIME__); printf("Result: \"%s\"\n", buffer); return 0; } ----------------------------------------------------------- Note how the va_list is constructed in the function that actually is a varargs one, in particular how the necessary parameter is mentioned. Note further how that va_list is passsed to the function that is not varargs in order to capture all variable arguments of its caller. There, no assumption on stack-layout. It will work with all types and ABIs, even those that happen to pass even some varargs in registers, not on the stack. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45249