Latest web development tutorials

C bibliothèque standard - <stdarg.h>

Brève introduction

fichier d' en- têtestdarg.h définit une variable de type va_listet trois macros, ces trois macros peut être utilisé dans un certain nombre de paramètres inconnus (ie, un nombre variable d'arguments) l' acquisition de paramètres de la fonction.

Les paramètres variables dans la liste des paramètres à la fin de la fonction est d'utiliser une ellipse (...) définition.

variantes de la bibliothèque

Voici un type de variable définie dans le fichier d'en-tête stdarg.h:

序号变量 & 描述
1va_list
这是一个适用于va_start()、va_arg()va_end()这三个宏存储信息的类型。

bibliothèque Macro

Ce qui suit est une macro définie dans le fichier d'en-tête stdarg.h:

序号宏 & 描述
1 void va_start(va_list ap, last_arg)
这个宏初始化ap变量,它与va_argva_end宏是一起使用的。last_arg是最后一个传递给函数的已知的固定参数,即省略号之前的参数。
2 type va_arg(va_list ap, type)
这个宏检索函数参数列表中类型为type的下一个参数。
3 void va_end(va_list ap)
这个宏允许使用了va_start宏的带有可变参数的函数返回。如果在从函数返回之前没有调用va_end,则结果为未定义。