From 82ba818ff456bcd6d56a06226e3f27e98fbb55c3 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 14 Aug 2025 22:58:58 -0500 Subject: removing all downloaded devdocs files --- devdocs/c/variadic.html | 62 ------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 devdocs/c/variadic.html (limited to 'devdocs/c/variadic.html') diff --git a/devdocs/c/variadic.html b/devdocs/c/variadic.html deleted file mode 100644 index a824c453..00000000 --- a/devdocs/c/variadic.html +++ /dev/null @@ -1,62 +0,0 @@ -

Variadic functions

Variadic functions are functions (e.g. printf) which take a variable number of arguments.

-

The declaration of a variadic function uses an ellipsis as the last parameter, e.g. int printf(const char* format, ...);. See variadic arguments for additional detail on the syntax and automatic argument conversions.

-

Accessing the variadic arguments from the function body uses the following library facilities:

- - - - - - - - -
Macros
Defined in header <stdarg.h>
enables access to variadic function arguments
(function macro)
accesses the next variadic function argument
(function macro)
-
(C99)
makes a copy of the variadic function arguments
(function macro)
ends traversal of the variadic function arguments
(function macro)
Type
holds the information needed by va_start, va_arg, va_end, and va_copy
(typedef)

Example

-

Print values of different types.

-
#include <stdio.h>
-#include <stdarg.h>
- 
-void simple_printf(const char* fmt, ...)
-{
-    va_list args;
-    va_start(args, fmt);
- 
-    while (*fmt != '\0') {
-        if (*fmt == 'd') {
-            int i = va_arg(args, int);
-            printf("%d\n", i);
-        } else if (*fmt == 'c') {
-            // A 'char' variable will be promoted to 'int'
-            // A character literal in C is already 'int' by itself
-            int c = va_arg(args, int);
-            printf("%c\n", c);
-        } else if (*fmt == 'f') {
-            double d = va_arg(args, double);
-            printf("%f\n", d);
-        }
-        ++fmt;
-    }
- 
-    va_end(args);
-}
- 
-int main(void)
-{
-    simple_printf("dcff", 3, 'a', 1.999, 42.5); 
-}

Output:

-
3
-a
-1.999000
-42.50000

References

See also

-
C++ documentation for Variadic functions
-

- © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
- https://en.cppreference.com/w/c/variadic -

-
-- cgit v1.2.3