Good Code
The good version states the required C version and uses const on the input pointer. CI can compile with strict flags and fail when the contract is not met.
Lesson 09
Make compiler assumptions visible in source so warning flags and language version mistakes fail during review or CI.
#include <stdlib.h>
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
#error "compile with C11 or newer"
#endif
int parse_review_score(const char *value)
{
// Source-level build contracts keep compiler assumptions visible.
if (value == NULL) {
return -1;
}
return atoi(value);
}#include <stdlib.h>
int parse_review_score(char *value)
{
// Missing build contracts let warnings stay optional.
return atoi(value);
}The good version states the required C version and uses const on the input pointer. CI can compile with strict flags and fail when the contract is not met.
The bad version leaves build assumptions outside the code. A project can compile it with weak flags and miss nullability, const, or standard-version problems.