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

typedef int (*FUNC)();
int diff_arg(int, FUNC);

int f0() {
   printf("f0() is called\n");
   return 0;
}

int f1(int arg1) {
  printf("f1() is called, argl = %d\n", arg1);
  return 0;
}

int f2(int arg1, int arg2) {
  printf("f2() is called, arg1 = %d, arg2 = %d\n", arg1, arg2);
  return 0;
}

int f3(int arg1, ...) {
   int i, vacount;
   va_list ap;

   printf("f3() is called, \narg1 = %d\n", arg1);
   va_start(ap, b);
   vacount = va_count(ap);
   for(i=0; i<vacount; i++) {
      if(va_elementtype(ap)  == elementtype(int)) {
         printf("arg%d = %d\n", i+2, va_arg(ap, int));
      }
      else if(va_elementtype(ap)  == elementtype(float)) {
         printf("arg%d = %f\n", i+2, va_arg(ap, float));
      }
      else if(va_elementtype(ap)  == elementtype(double)) {
         printf("arg%d = %f\n", i+2, va_arg(ap, double));
      }
   }
   return 0;
}



int main() {
  diff_arg(0, f0);
  diff_arg(0, NULL);
  diff_arg(1, (FUNC)f1);
  diff_arg(2, (FUNC)f2);
  diff_arg(INT_MAX, (FUNC)f3);
  return 0;
}
