]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man3/stdarg.3
Replaced tabs with spaces
[thirdparty/man-pages.git] / man3 / stdarg.3
index 9560b272e58b5ec76e0243531fb315211190c956..dd56df80a4b220ee24acdff48138139a3fe01ee7 100644 (file)
@@ -154,15 +154,15 @@ In such a setup (by far the most common) there seems
 nothing against an assignment
 .RS
 .nf
-       va_list aq = ap;
+    va_list aq = ap;
 .fi
 .RE
 Unfortunately, there are also systems that make it an
 array of pointers (of length 1), and there one needs
 .RS
 .nf
-       va_list aq;
-       *aq = *ap;
+    va_list aq;
+    *aq = *ap;
 .fi
 .RE
 Finally, on systems where parameters are passed in registers,
@@ -179,10 +179,10 @@ To accommodate this situation, C99 adds a macro
 so that the above assignment can be replaced by
 .RS
 .nf
-       va_list aq;
-       va_copy(aq, ap);
-       ...
-       va_end(aq);
+    va_list aq;
+    va_copy(aq, ap);
+    ...
+    va_end(aq);
 .fi
 .RE
 Each invocation of
@@ -205,30 +205,32 @@ with each format character based on the type.
 #include <stdio.h>
 #include <stdarg.h>
 
-void foo(char *fmt, ...) {
-       va_list ap;
-       int d;
-       char c, *s;
+void 
+foo(char *fmt, ...) 
+{
+    va_list ap;
+    int d;
+    char c, *s;
 
-       va_start(ap, fmt);
-       while (*fmt)
-               switch(*fmt++) {
-               case 's':                       /* string */
-                       s = va_arg(ap, char *);
-                       printf("string %s\en", s);
-                       break;
-               case 'd':                       /* int */
-                       d = va_arg(ap, int);
-                       printf("int %d\en", d);
-                       break;
-               case 'c':                       /* char */
-                       /* need a cast here since va_arg only
-                          takes fully promoted types */
-                       c = (char) va_arg(ap, int);
-                       printf("char %c\en", c);
-                       break;
-               }
-       va_end(ap);
+    va_start(ap, fmt);
+    while (*fmt)
+        switch(*fmt++) {
+        case 's':              /* string */
+            s = va_arg(ap, char *);
+            printf("string %s\en", s);
+            break;
+        case 'd':              /* int */
+            d = va_arg(ap, int);
+            printf("int %d\en", d);
+            break;
+        case 'c':              /* char */
+            /* need a cast here since va_arg only
+               takes fully promoted types */
+            c = (char) va_arg(ap, int);
+            printf("char %c\en", c);
+            break;
+        }
+    va_end(ap);
 }
 .fi
 .RE
@@ -254,16 +256,19 @@ The historic setup is:
 .nf
 #include <varargs.h>
 
-void foo(va_alist) va_dcl {
-       va_list ap;
+void 
+foo(va_alist) 
+    va_dcl 
+{
+    va_list ap;
 
-       va_start(ap);
-       while(...) {
-               ...
-               x = va_arg(ap, type);
-               ...
-       }
-       va_end(ap);
+    va_start(ap);
+    while(...) {
+        ...
+        x = va_arg(ap, type);
+        ...
+    }
+    va_end(ap);
 }
 .fi
 .RE