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]

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


On Wed, 07 Jun 2000, Carlo Wood wrote:
> 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.

Your code is wrong, it should read:

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

You are relying on implementation details otherwise.

Franz.
                                                                     

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