|
|
1.1 root 1: .TH VARARGS 3
2: .CT 2 data_man
3: .SH NAME
4: varargs \(mi variable argument list
5: .SH SYNOPSIS
6: .nf
7: .B #include <varargs.h>
8: .IB function (va_alist)
9: .B va_dcl
10: .PP
11: .B va_list pvar;
12: .PP
13: .B va_start(pvar);
14: .PP
15: .B va_arg(pvar, type);
16: .PP
17: .B va_end(pvar);
18: .fi
19: .SH DESCRIPTION
20: This set of macros allows portable procedures that accept variable
21: argument lists to be written.
22: Routines which have variable argument lists (such as
23: .IR printf (3))
24: that do not use varargs are inherently nonportable, since different
25: machines use different argument passing conventions.
26: .PP
27: The literal identifier
28: .I va_alist
29: is used in a function header to declare a variable argument list.
30: It is declared by
31: .I va_dcl.
32: Note that there is no semicolon after
33: .I va_dcl.
34: .PP
35: .B Va_list
36: is the type of the variable
37: .I pvar,
38: which is used to traverse the list.
39: One variable of this type must always be declared.
40: .PP
41: .I Va_start
42: initializes
43: .I pvar
44: to the beginning of the list.
45: .PP
46: .I Va_arg
47: returns the next argument in the list
48: pointed to by
49: .IR pvar .
50: .I Type
51: is the type the argument is expected to be.
52: Different types can be mixed, but it is up
53: to the routine to know what type is
54: expected, since it cannot be determined at runtime.
55: .PP
56: .I Va_end
57: is used to finish up.
58: .PP
59: Multiple traversals, each bracketed by
60: .I va_start
61: and
62: .I va_end,
63: are possible.
64: .SH EXAMPLES
65: How to define
66: .I execl
67: in terms of
68: .IR execv ;
69: see
70: .IR exec (2):
71: .IP
72: .nf
73: .ft L
74: #include <varargs.h>
75: execl(va_alist)
76: va_dcl
77: {
78: va_list ap;
79: char *file;
80: char *args[100];
81: int argno = 0;
82: va_start(ap);
83: file = va_arg(ap, char*);
84: while(args[argno++] = va_arg(ap, char*));
85: va_end(ap);
86: execv(file, args);
87: }
88: .fi
89: .ft P
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.