C中函数传入参数不确定问题

va_list: This type is used as a parameter for the macros defined incstdarg to retrieve the additional arguments of a function.

Each compiler may implement this type in its own way. It is only intended to be used as the type for the object used as first argument for theva_start, va_arg and va_end macros.

va_start is in charge of initializing an object of this type, so that subsequent calls tova_arg with it retrieve the additional arguments passed to the function.

Before a function that has initialized a va_list object with va_start returns, theva_end shall be executed.

 

example:

/* va_arg example */
#include <stdio.h>
#include <stdarg.h>

int FindMax ( int amount, ...)
{
  int i,val,greater;
  va_list vl;
  va_start(vl,amount);
  greater=va_arg(vl,int);
  for (i=1;i<amount;i++)
  {
    val=va_arg(vl,int);
    greater=(greater>val)?greater:val;
  }
  va_end(vl);
  return greater;
}

int main ()
{
  int m;
  m= FindMax (7,702,422,631,834,892,104,772);
  printf ("The greatest one is: %d\n",m);
  return 0;
}


 

 



 

你可能感兴趣的:(C中函数传入参数不确定问题)