C

Lesson 09

Compiler warning contracts

Make compiler assumptions visible in source so warning flags and language version mistakes fail during review or CI.

Good Code

src/review_parse.c
#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);
}

Bad Code

review_parse.c
#include <stdlib.h>

int parse_review_score(char *value)
{
    // Missing build contracts let warnings stay optional.
    return atoi(value);
}

Review Notes

What to review

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.

Bad Code

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.

Takeaways

  • Build assumptions belong near the code they protect, because reviewers cannot infer warning policy from a function body alone.