https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78868
Bug ID: 78868 Summary: When one variadic function calls another one, the parameters are reversed, if va_arg is used directly in function call. Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: vlad at cloudflare dot com Target Milestone: --- Created attachment 40374 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40374&action=edit Preprocessed source file On Debian 8, when using gcc 4.9.2, when one variadic function calls another one, the parameters are reversed, if va_arg is used directly in function call. When va_arg is evaluated before the call into a temporary location, the order is correct. Also replicated in gcc 5.3.1. Clang shows the expected behavior. #include <stdarg.h> int printf( const char* format, ... ); void vararg1(int n, ...) { va_list args; va_start(args, n); printf("%d, %d\n", va_arg(args, int), va_arg(args, int)); va_end(args); } void vararg2(int n, ...) { va_list args; va_start(args, n); int a = va_arg(args, int); int b = va_arg(args, int); printf("%d, %d\n", a, b); va_end(args); } int main() { vararg1(2, 12, 13); vararg2(2, 12, 13); return 0; } Gcc output: 13, 12 12, 13 Clang output: 12, 13 12, 13