varargs.3

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 3 代码 · 共 115 行

3
115
字号
.\" SCCSID: @(#)varargs.3	8.1	9/11/90.TH varargs 3 .SH Namevarargs \- variable argument list.SH Syntax.B "#include <varargs.h>".PP.I function\c.RB ( va_alist ).br.B va_dcl.br.B va_list.IR pvar ;.br.B va_start\c.RI ( pvar );.brf =.B va_arg\c.RI ( pvar ,.IR type );.br.B va_end\c.RI ( pvar );.SH Description.NXR "varargs subroutine".NXR "argument list" "portable procedures for variable"This set of macros provides a means of writing portable procedures thataccept variable argument lists.Routines having variable argument lists, such as.MS printf 3s ,that do not use varargs are inherently nonportable, since differentmachines use different argument passing conventions..PP.B va_alistis used in a function header to declare a variable argument list..PP.B va_dclis a declaration for.BR va_alist .Note that there is no semicolon after.B va_dcl..PP.B va_listis a type which can be used for the variable.IR pvar ,which is used to traverse the list.One such variable must always be declared..PP.B va_start\c.RI (pvar)is called to initialize.I pvarto the beginning of the list..PP.B va_arg\c.RI ( pvar ,.IR type )will return the next argument in the list pointed to by.IR pvar .The.I typeis the type the argument is expected to be.Different types can be mixed, but it is upto the routine to know what type of argument isexpected, since it cannot be determined at runtime..PP.B va_end\c.RI ( pvar )is used to finish up..PPMultiple traversals, each bracketed by.B va_start\&....B va_end,are possible..SH Examples.NXR "varargs subroutine" "example".EX#include <varargs.h>execl(va_alist)va_dcl{	va_list ap;	char *file;	char *args[100];	int argno = 0;	va_start(ap);	file = va_arg(ap, char *);	while (args[argno++] = va_arg(ap, char *))	B;	va_end(ap);	return execv(file, args);}.EE.SH Restrictions.NXR "varargs subroutine" "restrictions"It is up to the calling routine to determine how many argumentsthere are, since it is not possible to determine this from thestack frame.  For example,.PN execlpasses a 0 to signal the end of the list.The.PN printfcommand can tell how many arguments are supposed to be there by the format.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?