Problems using <varargs.h>

Chris Houck cs433aw at ux1.cso.uiuc.edu
Thu May 9 06:37:20 AEST 1991


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 at biobio.cs.uiuc.edu



More information about the Comp.unix.ultrix mailing list