This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
GCC-2.96: va_arg is ignored when its result is not used
- To: gcc-bugs at gcc dot gnu dot org
- Subject: GCC-2.96: va_arg is ignored when its result is not used
- From: Gaël Quéri <gael at baoule dot dyndns dot org>
- Date: Tue, 5 Oct 1999 13:46:36 +0200 (CEST)
In current gcc snapshots when the return value of va_arg is not used the
instruction is ignored and the va_list stays pointing the same arg.
I have included an example: in previous versions gcc returned 'arg2',
which is not the case anymore; moreover if the (void) is removed and the
compilation is made with -Wall gcc says that this statement has no effect.
This breaks at last glib, and certainly some more v*printf
implementations.
I don't know if these kind of things are allowed by the ISO standard, and
this could be easily fixed in the source by adding a temporary variable to
hold the result of va_arg, so this isn't a very grave problem, but there
is always a little source incompatibility.
I saw this problem on gcc-2.96 since 199909xx to 19991004 on ix86
architecture.
Good luck, gael
#include <stdarg.h>
#include <stdio.h>
void test (char *fmt, ...)
{
va_list args;
va_start (args, fmt);
(void) va_arg (args, char *);
puts (va_arg (args, char *));
}
int main ()
{
test ("%s %s", "arg1", "arg2");
return 0;
}