Checked C Language

Checked C is a research project from Microsoft research that attempts to make the C programming language safer for developers. Checked C is implemented as a Clang compiler for Windows and Linux. It provides a series of extensions to the C programming language that make it safer to use pointers directly, by implementing a few new pointer types as well as generics to replace the use of void pointers.

Details from the Microsoft Research homepage:

There are certain kinds of programming errors such as buffer overruns and incorrect type casts that programmers can make when writing C or C++ programs. These errors can lead to security vulnerabilities or software reliability problems. The Checked C extension will let programmers add checking to their programs to detect these kinds of errors when a program runs or while it is being written. Existing system software can be modified incrementally in a backwards-compatible fashion to have this checking.

In C, programmers use pointers to access data. A pointer is the address of a memory cell. It is easy for programmers to make mistakes when working with pointers, such that a program reads or writes the wrong data. These mistakes can cause programs to crash, misbehave, or allow the program to be taken over by a malicious adversary. Checked C allows programmers to better describe how they intend to use pointers and the range of memory occupied by data that a pointer points to. This information is then used to add checking at runtime to detect mistakes where the wrong data is accessed, instead of the error occurring silently and without detection. This information also can be used detect programming errors while the program is being written. The checking is called “bounds-checking” because it checks that data is being accessed within its intended bounds. The name Checked C reflects the fact that static and dynamic checking is being added to C.

Many programming languages already have bounds checking. C# and Java are examples of such languages. However, those languages automatically add the information needed for bounds checking to data structures. This is a problem for system software, where the programmer needs precise control over what a program is doing. In Checked C, the programmer controls the placement of information needed for bounds-checking and how the information flows through the program, so the programmer retains precise control over what a program is doing.

Checked C is hosted on GitHub with binaries available for Windows and nightly builds available for Windows and Linux users. You can learn more about language extensions added by Checked C here and there are several simple examples available here. You can learn more about the Checked C language in the video below.

Scroll to Top