/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include<stdio.h>
#include<stdarg.h>

struct tag1 {int i; int j;};
class tag2  {public: int i; int j;};
union tag3  {int i; double d;};

void f1(int i, ...) {
  va_list ap;
  struct tag1 s, *sp;
  class tag2 c, *cp;
  union tag3 u, *up;

  va_start(ap, arg_num);
  if(va_datatype(ap) == CH_STRUCTTYPE) {
    if(!strcmp(va_tagname(ap), "tag1"))
      s = va_arg(ap, struct tag1);
  }
  if(va_datatype(ap) == CH_STRUCTPTRTYPE) {
    if(!strcmp(va_tagname(ap), "tag1"))
      sp = va_arg(ap, struct tag1*);
  }

  if(va_datatype(ap) == CH_CLASSTYPE) {
    if(!strcmp(va_tagname(ap), "tag2"))
      c = va_arg(ap, class tag2);
  }
  if(va_datatype(ap) == CH_CLASSPTRTYPE) {
    if(!strcmp(va_tagname(ap), "tag2"))
      cp = va_arg(ap, class tag2*);
  }

  if(va_datatype(ap) == CH_UNIONTYPE) {
    if(!strcmp(va_tagname(ap), "tag3"))
      u = va_arg(ap, union tag3);
  }
  if(va_datatype(ap) == CH_UNIONPTRTYPE) {
    if(!strcmp(va_tagname(ap), "tag3"))
      up = va_arg(ap, union tag3*);
  }

  printf("i =  %d\n", i);
  printf("s.i = %d\n", s.i);
  printf("s.j = %d\n", s.j);
  printf("sp->i = %d\n", sp->i);
  printf("sp->j = %d\n", sp->j);
  printf("c.i = %d\n", c.i);
  printf("c.j = %d\n", c.j);
  printf("cp->i = %d\n", cp->i);
  printf("cp->j = %d\n", cp->j);
  printf("u.d = %f\n", u.d);
  printf("up->d = %f\n", up->d);
  va_end(ap);
}

int main(){
  struct tag1 s = {1,2};
  class tag2 c = {3,4};
  union tag3 u;
  u.d = 5;

  f1(10, s, &s, c, &c, u, &u);
}  


