Safe C

Adopting Safe C

Same code, any compiler

Safe C does not lock you in. Every annotation comes from one header, safec.h:

safec.h is a single file with no dependencies. The Safe C compiler ships it; for other compilers, copy clang/lib/Headers/safec.h into your project (Apache 2.0 with LLVM exceptions, like the rest of LLVM). -fsafe-c includes it automatically.

Adopting Safe C, one file at a time

Nobody annotates a whole codebase at once. Safe C is adopted per file, and the code builds and ships at every step.

Why a fork and not a set of flags

Even where Clang has a feature, a set of flags does not give a guarantee:

Standards and portability

The C standard committee is unlikely to adopt any of this soon, and it does not need to. Compiler extensions are how C has always moved: GNU C, __attribute__, Apple's blocks, Microsoft's SAL. Safe C code stays portable through safec.h (see Same code, any compiler).

The code is still C. It compiles with the normal C ABI and links with any C library.

Plain C libraries

A C library nobody checked is not safe to call, and Safe C does not try to make it so. Put its header in a -isystem directory and call it from a small function marked __unsafe, which is responsible for what it passes.

View the source of this page on GitHub