microsoft/checkedc logo

microsoft/checkedc

Free

Checked C is an extension to C that lets programmers write C code that is guaranteed by the compiler to be type-safe. The goal is to let people easily make their existing C code type-safe and eliminate entire classes of errors. Checked C does not address use-after-free errors. This repo has a wiki

FreeFree tier
Type
Open Source
Company
Microsoft

About microsoft/checkedc

Checked C is an open-source extension to the C programming language that adds bounds checking and improved type safety. Developed by Microsoft, it allows programmers to retrofit existing C code to be memory-safe by enforcing static and dynamic checks on pointer bounds and array accesses. The project includes a modified Clang compiler (fork of LLVM/Clang) that implements the extension, along with a specification, sample code, test suites, and a semi-automated conversion tool called 3C. Checked C does not address use-after-free errors, but additional research (e.g., Fat Pointers for temporal memory safety) has explored extending it further. The project has been presented at academic conferences and is actively maintained on GitHub.

Key Features

Bounds checking for pointer and array accesses
Improved type safety through static and dynamic checks
Semi-automated conversion tool (3C) to transform existing C code
Formal model verified with Coq theorem prover
Modified Clang compiler (LLVM fork) with downloadable binaries for Windows, Mac, and Ubuntu
Extensible design supports additional memory safety research (e.g., temporal safety via Fat Pointers)

Pros & Cons

Pros
  • Compiler-enforced safety catches many common C errors at compile or runtime
  • Incremental approach allows mixing checked and unchecked code
  • Open source and free to use
  • Backed by Microsoft and academic publications (IEEE, OOPSLA, etc.)
  • Includes a formal specification and a conversion tool to ease adoption
Cons
  • Does not address use-after-free errors (temporal memory safety)
  • Requires a modified compiler (Clang fork) not yet merged into mainline LLVM
  • May introduce runtime overhead due to bounds checks
  • Limited adoption outside of research and Microsoft projects
  • Learning curve for developers unfamiliar with the extension syntax

Best For

Retrofitting legacy C codebases to eliminate buffer overflows and memory corruptionDeveloping security-critical systems software with stronger safety guaranteesAcademic research into practical memory safety for systems languagesIncremental adoption: adding checked regions to existing C projects

FAQ

What is Checked C?
Checked C is an extension to the C programming language that adds bounds checking and improved type safety to help prevent memory corruption bugs. It is developed by Microsoft and available as an open-source project.
How does Checked C ensure safety?
Checked C introduces new pointer types and array bounds annotations that the compiler can statically verify or dynamically check at runtime. This prevents out-of-bounds accesses and helps enforce type safety.
Does Checked C prevent use-after-free errors?
No. Checked C focuses on spatial memory safety (bounds checking) and does not address temporal memory errors like use-after-free. However, related research has proposed extensions for temporal safety.
How can I convert existing C code to use Checked C?
The project provides a semi-automated tool called 3C that helps retrofit existing C code by suggesting or inserting checked annotations. You can also manually add annotations following the specification.