<cstdarg>

va_end

void va_end (va_list ap);
結束使用可變引數列表
對於一個已經使用 va_list 物件 ap 來檢索其額外引數的函式,執行適當的操作以確保其正常返回。

每當在函式中呼叫了 va_start 後,都應在該函式返回前呼叫此宏。

引數

ap
先前由 va_startva_copy 初始化的 va_list 物件。

返回值



示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* 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函式接受可變數量的引數。第一個傳入的引數成為引數first,但其餘的引數在 do-while 迴圈中使用 va_arg 順序檢索,直到檢索到空指標作為下一個引數為止。

輸出
First
Second
Third
Fourth


另見