summaryrefslogtreecommitdiff
path: root/share/man/man3/stdarg.3
diff options
context:
space:
mode:
authorHeikki Korpela <heko@cvs.openbsd.org>2001-08-13 16:54:10 +0000
committerHeikki Korpela <heko@cvs.openbsd.org>2001-08-13 16:54:10 +0000
commit1cec88d33a7fd9394e46e4a55c8c0105120061fd (patch)
treef18278ff07b498dce132da4d077eb075471cf43c /share/man/man3/stdarg.3
parentc07329174a2b69272e2e5a39701fc942c0c397c7 (diff)
- Note that unpromoted types should not be passed to va_arg
(see http://gcc.gnu.org/ml/gcc-patches/1999-09/msg00221.html) - Remove unused *p variable from example - Add a float example (mainly to point out that people shouldn't use float because it's promoted to double) ok millert@
Diffstat (limited to 'share/man/man3/stdarg.3')
-rw-r--r--share/man/man3/stdarg.333
1 files changed, 28 insertions, 5 deletions
diff --git a/share/man/man3/stdarg.3 b/share/man/man3/stdarg.3
index 01c12b8be15..061a8df504f 100644
--- a/share/man/man3/stdarg.3
+++ b/share/man/man3/stdarg.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: stdarg.3,v 1.7 2000/10/26 00:37:03 aaron Exp $
+.\" $OpenBSD: stdarg.3,v 1.8 2001/08/13 16:54:09 heko Exp $
.\" $NetBSD: stdarg.3,v 1.3 1994/11/30 15:24:37 jtc Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
@@ -124,9 +124,28 @@ to
If there is no next argument, or if
.Fa type
is not compatible with the type of the actual next argument
-(as promoted according to the default argument promotions),
+(as promoted according to the default argument promotions, see below),
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
@@ -154,8 +173,9 @@ associated with each format character based on the type.
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)
@@ -169,9 +189,12 @@ void foo(char *fmt, ...)
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);
}