This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Different behaviour of stdarg as function of platform, is this a bug?


The gcc implementation of stdarg is such that the behaviour
is different on different platforms.

I am wondering what is the correct ANSI behaviour, and if
gcc is conforming to this behaviour for all platforms or
that this is a bug.

Consider the little test program below; on most operating systems
the result is what I get (among others) on ix86/linux:

~/c/tests>uname -a
Linux jolan 2.3.99-pre9 #4 Tue May 16 16:10:46 CEST 2000 i686 unknown

~/c/tests>a.out
vfoo: 1 2
vfoo: 1 2

However, on ppc/linux (on a Mac - so far the only platform for which this
was reported to me) the result is:

$ uname -a
Linux www2.mhs.k12.oh.us 2.2.15pre3 #3 Sat Jan 29 18:02:45 CET 2000 ppc unknown

$ a.out
vfoo: 1 2
vfoo: 3 4

The reason for this difference is the difference in
/usr/lib/gcc-lib/ppc-redhat-linux/2.95.2/include/va-ppc.h compared to
the implementation used for ix86: on the ppc a "pointer" type is passed
to `vfoo' for the va_list, while on the ix86 it passes the va_list by value.
The former case causes `vl' to be changed after the first return from
vfoo() in the loop (now pointing to the third argument instead of the first).

Please keep the CC to me, as I am not subbed to this list.

-- 
Carlo Wood <carlo@alinoe.com>                           -=- Jesus Loves you -=-

The test program:

----------------------------------snip------------------------------------
#include <stdio.h>
#include <stdarg.h>

void vfoo(va_list vl)
{
  int a, b;
  a = va_arg(vl, int);
  b = va_arg(vl, int);
  printf("vfoo: %d %d\n", a, b);
}

void foo(int x, ...)
{
  int i;
  va_list vl;
  va_start(vl, x);
  for (i = 0; i < 2; ++i)
    vfoo(vl);
  va_end(vl);
}

int main(void)
{
  int a = 1, b = 2, c = 3, d = 4;
  foo(0, a, b, c, d);
  return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]