File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / man / man3 / varargs.3
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:26:57 2019 UTC (6 years, 11 months ago) by root
Branches: bsd, MAIN
CVS tags: v121, HEAD
Power 6/32 Unix version 1.21

.TH VARARGS 3  "19 January 1983"
.SH NAME
varargs \- variable argument list
.SH SYNOPSIS
.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 );
.br
f =
.B va_arg\c
.RI ( pvar ,
.IR type );
.br
.B va_end\c
.RI ( pvar );
.SH DESCRIPTION
This set of macros provides a means of writing portable procedures that
accept variable argument lists.
Routines having variable argument lists (such as
.IR printf (3))
that do not use varargs are inherently nonportable, since different
machines use different argument passing conventions.
.PP
.B va_alist
is used in a function header to declare a variable argument list.
.PP
.B va_dcl
is a declaration for
.BR va_alist .
Note that there is no semicolon after
.B va_dcl.
.PP
.B va_list
is 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 pvar
to the beginning of the list.
.PP
.B va_arg\c
.RI ( pvar ,
.IR type )
returns the next argument in the list pointed to by
.IR pvar .
.I Type
is the type the argument is expected to be.
Different types can be mixed, but it is up
to the routine to know what type of argument is
expected, since it cannot be determined at runtime.
.PP
.B va_end\c
.RI ( pvar )
is used to finish up.
.PP
Multiple traversals, each bracketed by
.B va_start
\&...
.B va_end,
are possible.
.SH EXAMPLE
.nf
	\fB#include\fP <varargs.h>
	execl(\fBva_alist\fP)
	\fBva_dcl\fP
	{
		\fBva_list\fP ap;
		\fBchar\fP *file;
		\fBchar\fP *args[100];
		\fBint\fP argno = 0;

		\fBva_start\fP(ap);
		file = \fBva_arg(ap, \fBchar\fP *);
		\fBwhile\fP (args[argno++] = \fBva_arg\fP(ap, \fBchar\fP *))
			\fB;\fP
		\fBva_end\fP(ap);
		\fBreturn\fP execv(file, args);
	}
.fi
.SH BUGS
It is up to the calling routine to determine how many arguments
there are, since it is not possible to determine this from the
stack frame.  For example,
.I execl
passes a 0 to signal the end of the list.
.I Printf
can tell how many arguments are supposed to be there by the format.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.