A runtime environment is the software and system context that supplies resources and services while a program executes. In C, main connects the application to the runtime system and follows standard entry-point rules. section 7.2
The C library supplies portable interfaces for common runtime services. An API can separate compiler implementations from library implementations, allowing combinations such as gcc or clang with different C libraries. section 8.0
Runtime-facing services include:
- Program startup and termination: main returns EXIT_SUCCESS or EXIT_FAILURE, while exit terminates execution without returning to its caller. section 7.2
- Environment access: programs read name-value pairs such as HOME, PATH, LANG, and LC_ALL through environment functions. section 8.7
- Locale control: programs inspect or change language, numeric, time, and character-handling settings with setlocale. section 8.7
A portable program boundary
Use one of the two standard forms: int main(void); or int main(int argc, char* argv[argc+1]);. Reaching the end of main is equivalent to returning EXIT_SUCCESS. section 7.2
void printenv(char const name[static 1]) {
if (getenv(name)) {
char value[256] = { };
if (getenv_s(nullptr, value, sizeof value, name)) {
fprintf(stderr,
"%s: value is longer than %zu\n",
name, sizeof value);
} else {
printf("%s=%s\n", name, value);
}
} else {
fprintf(stderr, "%s not in environment\n", name);
}
}
This listing demonstrates checking for an environment variable, copying it into a bounded buffer, and reporting an oversized value. section 8.7



