Modular C
Static Helper
A static helper function keeps implementation details private to one source file.
Static Helper
static_helper.c
#include <stdio.h>
static int clamp_to_limit(int value) {
if (value > 10) {
return 10;
}
return value;
}
int main(void) {
int input = ;
int clamped = clamp_to_limit(input);
printf("clamped=%d\n", clamped);
return 0;
}
#include <stdio.h>
static int clamp_to_limit(int value) {
if (value > 10) {
return 10;
}
return value;
}
int main(void) {
int input = ;
int clamped = clamp_to_limit(input);
printf("clamped=%d\n", clamped);
return 0;
}
#include <stdio.h>
static int clamp_to_limit(int value) {
if (value > 10) {
return 10;
}
return value;
}
int main(void) {
int input = ;
int clamped = clamp_to_limit(input);
printf("clamped=%d\n", clamped);
return 0;
}
internal linkage
At file scope, `static` limits a helper function to the current translation unit.
small boundary
The public code calls a named operation while the helper owns one detail.