C Programming • C17 baseline, standards-specific features labeled
Optional and Version-Specific C Features
Know which language facilities are optional, version-dependent, or unsuitable for a portable interface.
Some facilities, including variable-length arrays in modern C revisions and parts of the optional Annex K library, are not uniformly implemented. Check the compiler and library documentation, provide a fallback, and avoid making optional features mandatory without a deployment reason.
Example
#include <stddef.h>
int sum_fixed(const int values[], size_t count) {
int sum = 0;
for (size_t i = 0; i < count; ++i) {
sum += values[i];
}
return sum;
}
What to expect
A pointer-plus-length interface avoids requiring a variable-length local array.
Key idea: Prefer a portable interface when an optional feature does not materially improve safety or clarity.