stdarg
A wrapper for <stdarg.h>
Wraps a native library — check OS Compatibility below for platform-specific linking notes.
Summary
| Latest Version | Unknown |
|---|---|
| License | MIT |
| CI Status | Failing |
| Downloads | 0 |
| Last Indexed | 2026-07-21 05:25 |
Tags
Installation
nimble install stdarg
choosenim install stdarg
git clone https://github.com/sls1005/stdarg
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| stdarg | ✓ | ✓ | ✓ | - | - | - | - | - | - | - |
Source
| Repository | https://github.com/sls1005/stdarg |
|---|---|
| Homepage | https://github.com/sls1005/stdarg |
| Registry Source | nimble_official |
README
Nim stdarg
This is a Nim wrapper for the standard C header <stdarg.h>. One can use it to make variadic procedures that can be used from C/C++.
Standard C functions that take va_list (the list object, not "...") as arguments are also wrapped (those from <stdio.h> are in stdarg/io, and those from <wchar.h> in stdarg/wchar).
Example
import stdarg
proc sum(x: int): int {.varargs.} =
var
args {.noInit.}: VAList
a: int
args.init(x)
result = x
while true:
args.next(a)
if a == 0:
break
result += a
echo sum(1, 2, 3, 0)
To make a procedure that takes variable number of parameters, mark it as {.varargs.} and declare a variable of type VAList. After that, call init with the last parameter name to initialize it. Use next to store the next argument into a variable.
Note that {.varargs.} is a built-in pragma. It tells the compiler that the procedure is able to take more arguments.
Note
-
This package is only useful when interacting with C/C++. The built-in
varargs[T]should be used in other cases. -
For each
VAListinitialized withinit(),va_endwill be automatically invoked (and thus don't need to be called explicitly). For aVAListinitialized with another method,va_endmust be called once in the same proc as it initialized. However it don't need to be invoked if the list is never initialized.
References
- https://cplusplus.com/reference/cstdarg/
- https://cplusplus.com/reference/cstdio/
- https://cplusplus.com/reference/cwchar/
- https://en.cppreference.com/w/c/experimental/dynamic/asprintf