Possible Implementation of ANSI C stdarg.h on IA-32

#include <stdio.h>

typedef char* vay_list;

#define vay_rounded_size(type) \
  (((sizeof (type) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))

#define vay_start(ap, v) \
  ((void) (ap = (vay_list) &v + vay_rounded_size (v)))

#define vay_arg(ap, type) \
  (ap += vay_rounded_size (type), *((type *)(ap - vay_rounded_size (type))))

#define vay_end(ap) ((void) (ap = 0))


void PrintFloats (int amount, ...)
{
  int i;
  double vayl;
  printf ("Floats passed: ");
  vay_list vl;

  vay_start(vl,amount);

  for (i=0;i<amount;i++)
  {
    vayl=vay_arg(vl,double);
    printf ("\t%.2f",vayl);
  }

  vay_end(vl);

  printf ("\n");
}

int main ()
{
  PrintFloats (3,3.14159,2.71828,1.41421);
  return 0;
}
 

你可能感兴趣的:(C++,c,C#)