Message-ID: <394F94BB.67B7C80E@softhome.net> Date: Tue, 20 Jun 2000 17:58:51 +0200 From: Laurynas Biveinis X-Mailer: Mozilla 4.73 [en] (Win98; U) X-Accept-Language: lt,en MIME-Version: 1.0 To: Eli Zaretskii CC: DJGPP Workers Subject: Re: Patch: new GCC builtins for stdarg.h/varargs.h References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Eli Zaretskii wrote: > If you can run the trivial implementation via some test suite that proves > that it indeed works, then I agree. How about following? It should print 10 20 24 And it does that with both trivial and builtin va_copy implementation. What are additional cases which should be tested? #include #include /* At least two additional ints should be passed. */ /* The last arg should be zero. */ void magic_sum(int first, ...) { va_list args; va_list arg_copy; int i, sum = first; va_start(args, first); /* Sum up everything twice */ va_copy(arg_copy, args); do { i = va_arg(args, int); sum += i; } while (i); printf("Now %d\n", sum); sum += first; do { i = va_arg(arg_copy, int); sum += i; } while (i); printf("Now %d\n", sum); /* Add everything one more time except first three args. */ va_start(arg_copy, first); va_arg(arg_copy, int); va_arg(arg_copy, int); va_copy(args, arg_copy); do { i = va_arg(arg_copy, int); sum += i; } while (i); printf("And finally %d\n", sum); va_end(args); va_end(arg_copy); } int main(void) { magic_sum(1, 2, 3, 4, 0); return 0; }