Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/share/man/man3 mention argument promotion and change example
details: https://anonhg.NetBSD.org/src/rev/483992321a29
branches: trunk
changeset: 535424:483992321a29
user: yamt <yamt%NetBSD.org@localhost>
date: Sun Aug 18 08:57:07 2002 +0000
description:
mention argument promotion and change example
as well.
from OpenBSD.
diffstat:
share/man/man3/stdarg.3 | 41 ++++++++++++++++++++++++++++++++---------
1 files changed, 32 insertions(+), 9 deletions(-)
diffs (86 lines):
diff -r 5ddd5eb000ff -r 483992321a29 share/man/man3/stdarg.3
--- a/share/man/man3/stdarg.3 Sun Aug 18 08:03:35 2002 +0000
+++ b/share/man/man3/stdarg.3 Sun Aug 18 08:57:07 2002 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: stdarg.3,v 1.14 2002/02/13 08:17:30 ross Exp $
+.\" $NetBSD: stdarg.3,v 1.15 2002/08/18 08:57:07 yamt Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -37,7 +37,7 @@
.\"
.\" @(#)stdarg.3 8.1 (Berkeley) 6/5/93
.\"
-.Dd April 14, 2001
+.Dd August 18, 2002
.Dt STDARG 3
.Os
.Sh NAME
@@ -131,6 +131,25 @@
(as promoted according to the default argument promotions),
random errors will occur.
.Pp
+If the type in question is one that gets promoted, the promoted type
+should be used as the argument to
+.Fn va_arg .
+The following describes which types are promoted (and to what):
+.Bl -dash -compact
+.It
+.Va short
+is promoted to
+.Va int
+.It
+.Va float
+is promoted to
+.Va double
+.It
+.Va char
+is promoted to
+.Va int
+.El
+.Pp
The first use of the
.Fn va_arg
macro after that of the
@@ -170,18 +189,20 @@
macro returns no value.
.Sh EXAMPLES
The function
-.Em foo
+.Fn foo
takes a string of format characters and prints out the argument
associated with each format character based on the type.
.Bd -literal -offset indent
-void foo(char *fmt, ...)
+void
+foo(char *fmt, ...)
{
va_list ap;
- int d;
- char c, *p, *s;
+ int d, c;
+ char *s;
+ double f;
va_start(ap, fmt);
- while (*fmt) {
+ while (*fmt)
switch (*fmt++) {
case 's': /* string */
s = va_arg(ap, char *);
@@ -192,11 +213,13 @@
printf("int %d\en", d);
break;
case 'c': /* char */
- c = va_arg(ap, char);
+ c = va_arg(ap, int); /* promoted */
printf("char %c\en", c);
break;
+ case 'f': /* float */
+ f = va_arg(ap, double); /* promoted */
+ printf("float %f\en", f);
}
- }
va_end(ap);
}
.Ed
Home |
Main Index |
Thread Index |
Old Index