[comp.unix.ultrix] Problems using <varargs.h>

cs433aw@ux1.cso.uiuc.edu (Chris Houck) (05/09/91)

Hi, I'm getting some really weird behavior with using the <varargs.h> package
under Ultrix 4.1.   I'm trying to run the following program --- when the
size of structure xxx is 12 or less I get the normal behavior, but when I
increase xxx to size 16 (by uncommenting the "int d;" line) I don't get
the correct values for the data I try to read with va_arg().

Any ideas?  Should I be using a different variable argument package?
(This is with both MIPS cc 2.0 and gcc 1.37.1 --- It works on one of the local
Multimaxes, but I'd rather not work there...)

/* --------------------------------------------------------------- */
#include <stdio.h>
#include <varargs.h>

typedef struct XXX  {
  int a,b,c;
/*  int d; */
} xxx;

test(first, va_alist)
xxx first;
va_dcl
{
  va_list ap;
  xxx data;

  va_start(ap);
  data = va_arg(ap, xxx);
  va_end(ap);

  printf("%d %d\n", first.a, first.b);
  printf("%d %d\n", data.a, data.b);
  printf("sizeof = %d\n", sizeof(xxx));
}


main() {
  xxx a, b;
  a.a = 1; a.b = 16;
  b.a = 5; b.b = 15;
  test(a, b);
}

/* ------------------------------------------------------------ */

output when sizeof(xxx) == 12 :
1 16
5 15
sizeof = 12

output when sizeof(xxx) == 16 :
1 16
0 0
sizeof = 16


Thanks in adavance,
-Chris Houck

houck@biobio.cs.uiuc.edu

farrell@pangea.Stanford.EDU (Phil Farrell) (05/10/91)

In article <1991May8.203720.6846@ux1.cso.uiuc.edu> cs433aw@ux1.cso.uiuc.edu (Chris Houck) writes:
>Hi, I'm getting some really weird behavior with using the <varargs.h> package
>under Ultrix 4.1.   I'm trying to run the following program --- when the
>size of structure xxx is 12 or less I get the normal behavior, but when I
>increase xxx to size 16 (by uncommenting the "int d;" line) I don't get
>the correct values for the data I try to read with va_arg().

Well, I think you need to get on the phone to DEC Ultrix support and 
request the "ULTRIX XPG3 Upgrade" tape.  I do not have the tape, but 
I have the DEC document entitled "ULTRIX/UWS Version 4.1 XPG3 Upgrade",
DEC order # AA-PE9UA-TE, which states:
	"On RISC platforms, the default system C compiler does not 
	correctly handle the varargs calling sequence when structures
	are passed.  However, pointers, integers, and floating point
	numbers are handled correctly.  The ULTRIX/UWS Version 4.1
	XPG3 Upgrade release includes a new version of the C compiler
	that corrects this problem."

-Phil Farrell, Computer Systems Manager
Stanford University School of Earth Sciences
farrell@pangea.stanford.edu