BSD 4_3_Net_2 release
[unix-history] / usr / src / share / man / man3 / stdarg.3
index 89360f6..8f1e782 100644 (file)
-.\" Copyright (c) 1990 The Regents of the University of California.
+.\" Copyright (c) 1990, 1991 The Regents of the University of California.
 .\" All rights reserved.
 .\"
 .\" All rights reserved.
 .\"
-.\" %sccs.include.redist.man%
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
 .\"
 .\"
-.\"    @(#)stdarg.3    6.4 (Berkeley) %G%
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"    This product includes software developed by the University of
+.\"    California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
 .\"
 .\"
-.TH VARARGS 3  ""
-.AT 3
-.SH NAME
-varargs \- variable argument lists
-.SH SYNOPSIS
-.nf
-.ft B
-#include <stdarg.h>
-
-void
-va_start(va_list ap, last);
-
-type
-va_arg(va_list ap, type);
-
-void
-va_end(va_list ap);
-.ft R
-.fi
-.SH DESCRIPTION
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"    @(#)stdarg.3    6.8 (Berkeley) 6/29/91
+.\"
+.Dd June 29, 1991
+.Dt STDARG 3
+.Os
+.Sh NAME
+.Nm stdarg
+.Nd variable argument lists
+.Sh SYNOPSIS
+.Fd #include <stdarg.h>
+.Ft void
+.Fn va_start "va_list ap" last
+.Ft type
+.Fn va_arg "va_list ap" type
+.Ft void
+.Fn va_end "va_list ap"
+.Sh DESCRIPTION
 A function may be called with a varying number of arguments of varying
 types.
 The include file
 A function may be called with a varying number of arguments of varying
 types.
 The include file
-.I <stdarg.h>
-declares a type (\fIva_list\fP) and defines three macros for stepping
+.Aq Pa stdarg.h
+declares a type
+.Pq Em va_list
+and defines three macros for stepping
 through a list of arguments whose number and types are not known to
 the called function.
 through a list of arguments whose number and types are not known to
 the called function.
-.PP
+.Pp
 The called function must declare an object of type
 The called function must declare an object of type
-.I va_list
+.Em va_list
 which is used by the macros
 which is used by the macros
-.IR va_start ,
-.IR va_arg ,
+.Fn va_start ,
+.Fn va_arg ,
 and
 and
-.IR va_end .
-.PP
+.Fn va_end .
+.Pp
 The
 The
-.I va_start
+.Fn va_start
 macro initializes
 macro initializes
-.I ap
+.Fa ap
 for subsequent use by
 for subsequent use by
-.I va_arg
+.Fn va_arg
 and
 and
-.IR va_end ,
+.Fn va_end ,
 and must be called first.
 and must be called first.
-.PP
+.Pp
 The parameter
 The parameter
-.I last
+.Fa last
 is the name of the last parameter before the variable argument list,
 i.e. the last parameter of which the calling function knows the type.
 is the name of the last parameter before the variable argument list,
 i.e. the last parameter of which the calling function knows the type.
-.PP
+.Pp
 Because the address of this parameter is used in the
 Because the address of this parameter is used in the
-.I va_start
+.Fn va_start
 macro, it should not be declared as a register variable, or as a
 macro, it should not be declared as a register variable, or as a
-function or array type.
-.PP
+function or an array type.
+.Pp
 The
 The
-.I va_start
+.Fn va_start
 macro returns no value.
 macro returns no value.
-.PP
+.Pp
 The
 The
-.I va_arg
+.Fn va_arg
 macro expands to an expression that has the type and value of the next
 argument in the call.
 The parameter
 macro expands to an expression that has the type and value of the next
 argument in the call.
 The parameter
-.I ap
+.Fa ap
 is the 
 is the 
-.I va_list ap
+.Em va_list Fa ap
 initialized by
 initialized by
-.IR va_start .
+.Fn va_start .
 Each call to 
 Each call to 
-.I va_arg 
+.Fn va_arg
 modifies
 modifies
-.I ap
+.Fa ap
 so that the next call returns the next argument.
 The parameter
 so that the next call returns the next argument.
 The parameter
-.I type
+.Fa type
 is a type name specified so that the type of a pointer to an
 object that has the specified type can be obtained simply by 
 is a type name specified so that the type of a pointer to an
 object that has the specified type can be obtained simply by 
-adding a 
-.I *
+adding a *
 to
 to
-.IR type .
-.PP
+.Fa type .
+.Pp
 If there is no next argument, or if
 If there is no next argument, or if
-.I type
+.Fa type
 is not compatible with the type of the actual next argument
 (as promoted according to the default argument promotions),
 random errors will occur.
 is not compatible with the type of the actual next argument
 (as promoted according to the default argument promotions),
 random errors will occur.
-.PP
+.Pp
 The first use of the
 The first use of the
-.I va_arg
+.Fn va_arg
 macro after that of the 
 macro after that of the 
-.I va_start 
+.Fn va_start
 macro returns the argument after 
 macro returns the argument after 
-.IR last .
+.Fa last .
 Successive invocations return the values of the remaining
 arguments.
 Successive invocations return the values of the remaining
 arguments.
-.PP
+.Pp
 The
 The
-.I va_end
+.Fn va_end
 macro handles a normal return from the function whose variable argument
 list was initialized by 
 macro handles a normal return from the function whose variable argument
 list was initialized by 
-.IR va_start .
-.PP
+.Fn va_start .
+.Pp
 The
 The
-.I va_end
+.Fn va_end
 macro returns no value.
 macro returns no value.
-.SH STANDARDS
-The
-.IR va_start ,
-.IR va_arg ,
-and
-.I va_end
-macros are ANSI C compatible.
-.SH COMPATIBILITY
-These macros are
-.B not
-compatible with the historic macros they replace.
-A backward compatible version can be found in the include
-file 
-.IR <varargs.h> .
-.SH EXAMPLES
+.Sh EXAMPLES
 The function
 The function
-.I foo
+.Em foo
 takes a string of format characters and prints out the argument
 associated with each format character based on the type.
 takes a string of format characters and prints out the argument
 associated with each format character based on the type.
-.sp
-.nf
-.RS
-foo(fmt)
-       char *fmt;
+.Bd -literal -offset indent
+void foo(char *fmt, ...)
 {
        va_list ap;
        int d;
 {
        va_list ap;
        int d;
@@ -160,4 +169,37 @@ foo(fmt)
                }
        va_end(ap);
 }
                }
        va_end(ap);
 }
-.fi
+.Ed
+.Sh STANDARDS
+The
+.Fn va_start ,
+.Fn va_arg ,
+and
+.Fn va_end
+macros conform to
+.St -ansiC .
+.Sh COMPATIBILITY
+These macros are
+.Em not
+compatible with the historic macros they replace.
+A backward compatible version can be found in the include
+file 
+.Aq Pa varargs.h .
+.Sh BUGS
+Unlike the
+.Em varargs
+macros, the
+.Nm stdarg
+macros do not permit programmers to
+code a function with no fixed arguments.
+This problem generates work mainly when converting
+.Em varargs
+code to
+.Nm stdarg
+code,
+but it also creates difficulties for variadic functions that
+wish to pass all of their arguments on to a function
+that takes a
+.Em va_list
+argument, such as
+.Xr vfprintf 3 .