CKTIS / C
static — storage duration and linkage
The meaning of static depends on context: a persistent local object, internal linkage, or a required argument-array size.
Version: C23; repository compiler flag, production runtime not attested
Syntax
static int total;
static int next(void);
void use(int a[static 3]);
(static int){0}Inside a block, static used without thread_local gives an object static storage duration: its value persists between calls, but its name remains local. Such an object is initialized before program startup; an integer object with no initializer is initialized to zero. In C23, a block-scope object declared with both static and thread_local has thread storage duration, not static storage duration.
At file scope, static gives an object or function name internal linkage — within its translation unit. Storage duration applies to objects, not functions.
The parameter int a[static 3] adjusts to a pointer. On every call, the argument must provide access to the first element of an array with at least three elements. A pointer to the last element of a three-element array does not satisfy this requirement. This is not bounds checking.
C23 also permits the compound literal (static int){0} with static storage duration. static provides no thread synchronization.
Examples
#include <stdio.h>
static int next(void)
{
static int count;
return ++count;
}
int main(void)
{
printf("%d\n", next());
printf("%d\n", next());
return 0;
}
Result
1 2
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.