Home C&C++函数库 c++ 语法 程序源码 Linux C库

va_end

macro   <cstdarg>

void va_end (va_list ap);

使用变量参数列表结束

通过使用va_list对象ap检索其附加参数的函数,执行相应的操作以正常返回。

当从函数调用va_start时,这个宏应该在函数返回之前被调用。

☲  参数


ap

之前由va_startva_copy初始化的va_list对象。

☉  返回值



none

☣  示例



/* va_end example */
#include <stdio.h>      /* puts */
#include <stdarg.h>     /* va_list, va_start, va_arg, va_end */

void PrintLines (char* first, ...)
{
  char* str;
  va_list vl;

  str=first;

  va_start(vl,first);

  do {
    puts(str);
    str=va_arg(vl,char*);
  } while (str!=NULL);

  va_end(vl);
}

int main ()
{
  PrintLines ("First","Second","Third","Fourth",NULL);
  return 0;
}

PrintLines函数接受数量可变的参数。传递的第一个参数首先成为形参, 但其余的使用va_arg在do-while循环中顺序检索,直到检索到下一个参数为一个空指针。
输出:
First
Second
Third
Fourth

🍄  另请参阅


va_list 保存关于变量参数的信息的类型(type)
va_start 初始化变量参数列表(宏)
va_arg 检索下一个参数(宏)

联系我们 免责声明 关于CandCplus 网站地图