CKTIS / C
va_end — finish using an argument list
va_end from <stdarg.h> finishes using a va_list. Each va_start or va_copy requires a matching va_end in the same function.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <stdarg.h>
void va_end(va_list ap);va_end(ap) from <stdarg.h> finishes using a va_list and returns no value. The standard describes it as a macro but also permits implementation as an identifier with external linkage.
Each va_start and va_copy requires a matching va_end in the same function before returning, including early returns. Omitting it or calling it without a matching initialization causes undefined behavior.
After va_end, do not reuse ap without initialization by va_start or va_copy. You need not read all arguments first.
Examples
#include <stdarg.h>
#include <stdio.h>
static int sum(int count, ...)
{
va_list ap;
va_start(ap, count);
int total = 0;
for (int i = 0; i < count; ++i) {
total += va_arg(ap, int);
}
va_end(ap);
return total;
}
int main(void)
{
printf("%d\n", sum(3, 10, 20, 30));
return 0;
}Result
60
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.