stdarg.3 (9cbda59000e0f366b04c83d8d852c7c34b467722) | stdarg.3 (484e5bdd2bb59ca12aa3235e5fb2474c6966e193) |
---|---|
1.\" Copyright (c) 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the American National Standards Committee X3, on Information 6.\" Processing Systems. 7.\" 8.\" Redistribution and use in source and binary forms, with or without --- 45 unchanged lines hidden (view full) --- 54.Fn va_end "va_list ap" 55.Sh DESCRIPTION 56A function may be called with a varying number of arguments of varying 57types. 58The include file 59.In stdarg.h 60declares a type 61.Pq Em va_list | 1.\" Copyright (c) 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the American National Standards Committee X3, on Information 6.\" Processing Systems. 7.\" 8.\" Redistribution and use in source and binary forms, with or without --- 45 unchanged lines hidden (view full) --- 54.Fn va_end "va_list ap" 55.Sh DESCRIPTION 56A function may be called with a varying number of arguments of varying 57types. 58The include file 59.In stdarg.h 60declares a type 61.Pq Em va_list |
62and defines three macros for stepping | 62and defines four macros for stepping |
63through a list of arguments whose number and types are not known to 64the called function. 65.Pp 66The called function must declare an object of type 67.Em va_list 68which is used by the macros 69.Fn va_start , 70.Fn va_arg , 71.Fn va_copy , 72and 73.Fn va_end . 74.Pp 75The 76.Fn va_start 77macro initializes 78.Fa ap 79for subsequent use by | 63through a list of arguments whose number and types are not known to 64the called function. 65.Pp 66The called function must declare an object of type 67.Em va_list 68which is used by the macros 69.Fn va_start , 70.Fn va_arg , 71.Fn va_copy , 72and 73.Fn va_end . 74.Pp 75The 76.Fn va_start 77macro initializes 78.Fa ap 79for subsequent use by |
80.Fn va_arg | 80.Fn va_arg , 81.Fn va_copy , |
81and 82.Fn va_end , 83and must be called first. 84.Pp 85The parameter 86.Fa last 87is the name of the last parameter before the variable argument list, 88i.e., the last parameter of which the calling function knows the type. 89.Pp 90Because the address of this parameter is used in the 91.Fn va_start 92macro, it should not be declared as a register variable, or as a 93function or an array type. 94.Pp 95The | 82and 83.Fn va_end , 84and must be called first. 85.Pp 86The parameter 87.Fa last 88is the name of the last parameter before the variable argument list, 89i.e., the last parameter of which the calling function knows the type. 90.Pp 91Because the address of this parameter is used in the 92.Fn va_start 93macro, it should not be declared as a register variable, or as a 94function or an array type. 95.Pp 96The |
96.Fn va_start 97macro returns no value. 98.Pp 99The | |
100.Fn va_arg 101macro expands to an expression that has the type and value of the next 102argument in the call. 103The parameter 104.Fa ap 105is the 106.Em va_list Fa ap 107initialized by | 97.Fn va_arg 98macro expands to an expression that has the type and value of the next 99argument in the call. 100The parameter 101.Fa ap 102is the 103.Em va_list Fa ap 104initialized by |
108.Fn va_start . | 105.Fn va_start 106or 107.Fn va_copy . |
109Each call to 110.Fn va_arg 111modifies 112.Fa ap 113so that the next call returns the next argument. 114The parameter 115.Fa type 116is a type name specified so that the type of a pointer to an --- 30 unchanged lines hidden (view full) --- 147with the same second argument used with 148.Fa src , 149and calling 150.Fn va_arg 151the same number of times as called with 152.Fa src . 153.Pp 154The | 108Each call to 109.Fn va_arg 110modifies 111.Fa ap 112so that the next call returns the next argument. 113The parameter 114.Fa type 115is a type name specified so that the type of a pointer to an --- 30 unchanged lines hidden (view full) --- 146with the same second argument used with 147.Fa src , 148and calling 149.Fn va_arg 150the same number of times as called with 151.Fa src . 152.Pp 153The |
155.Fn va_copy 156macro returns no value. | 154.Fn va_end 155macro cleans up any state associated with the variable argument list 156.Fa ap . |
157.Pp | 157.Pp |
158The | 158Each invocation of 159.Fn va_start 160or 161.Fn va_copy 162must be paired with a corresponding invocation of |
159.Fn va_end | 163.Fn va_end |
160macro handles a normal return from the function whose variable argument 161list was initialized by 162.Fn va_start . | 164in the same function. 165.Sh RETURN VALUES 166The 167.Fn va_arg 168macro returns the value of the next argument. |
163.Pp 164The | 169.Pp 170The |
171.Fn va_start , 172.Fn va_copy , 173and |
|
165.Fn va_end | 174.Fn va_end |
166macro returns no value. | 175macros return no value. |
167.Sh EXAMPLES 168The function 169.Em foo 170takes a string of format characters and prints out the argument 171associated with each format character based on the type. 172.Bd -literal -offset indent 173void foo(char *fmt, ...) 174{ --- 58 unchanged lines hidden --- | 176.Sh EXAMPLES 177The function 178.Em foo 179takes a string of format characters and prints out the argument 180associated with each format character based on the type. 181.Bd -literal -offset indent 182void foo(char *fmt, ...) 183{ --- 58 unchanged lines hidden --- |