[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gcc 2.8.1 va_arg problem




   [This is perhaps not the right place to ask but I have
   this problem only with OpenBSD. AIX, HP-UX, Solaris, 
   and Windows NT do not show this behavior]

   I have some some problems with porting a large comercial
   application to OpenBSD 2.5/i386 with gcc 2.8.1. The problem
   seems to be a function with variable parameters. I build
   a short test case that does NOT produce the expected result
   (Var = 1024). It DOES return the correct value if the last  
   parameter of test is an int. 
   If I debug the program with gdb it seems that the parameter
   v gets copied to another place (not where the other parameter
   are on the stack).
   It seems that a normal stack frame is build like that:

      [local var 1] [local var 2] ... [return address] 
      [para 1] [para 2] ...

   In my case the address of the variable v in the function test
   gets an address within the local variables and the va_start
   macros fails.
 
   Any ideas where the problem is (gcc or me)?

   Thanks for your time. 

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

int	test (void* p, short int v, ...);

main ()
{
	int a;
	a= 20;

	test (&a, a, (long) 1024);
}

int	test (void* p, short int v, ...)
{
	long var;
	va_list ap;

	va_start (ap, v);
	var= va_arg (ap, long);
	va_end (ap);
	printf ("Var = %ld\n", var);
}

   ------------------------------------------------------------
   Martin Portmann                         Phone +41-41-7832720
   infinitum AG, Switzerland                 Fax +41-41-7832721
   Software Solutions                          www.infinitum.ch