Abstract
The C programming language, known for its power and efficiency, is ubiquitous in systemsprogramming, embedded systems, and other performance-critical applications. However, its
flexibility and low-level capabilities often come with significant risks, including common vul-
nerabilities such as buffer overflows, integer overflows, and null pointer dereferences. These
issues compromise both the security and reliability of software systems, necessitating innova-
tive approaches to enhance the safety and maintainability of C programs without sacrificing
their inherent performance advantages.
This thesis proposes the integration of advanced contract programming features into C, in-
troducing a proposed syntax that includes requires, ensures, invariant, checked, and unchecked
keywords. These elements are designed to embed rigorous, self-checking mechanisms directly
into the code, enhancing safety, clarity, and maintainability. The requires and ensures keywords
allow for explicit declaration of preconditions and postconditions, respectively, thereby facilitat-
ing early detection and prevention of errors. The invariant keyword helps maintain consistent
states within loops and functions, while checked and unchecked blocks offer the flexibility to
optimize performance by selectively enabling or disabling runtime checks.
The theoretical framework developed in this thesis explores the potential of these features to
mitigate common programming errors and enhance the code’s documentation and readability.
The proposed model aims to strike a balance between safety and performance, providing tools
that make C code both safer and easier to manage.
Future work is directed towards the practical implementation of these concepts, including
the development of a prototype compiler or preprocessor that understands and processes the
proposed syntax. Additionally, this thesis outlines the necessity for automated refactoring tools,
performance impact studies, and safety guidelines for the optimal use of unchecked blocks.
Long-term studies on maintenance and error rates in real-world projects are also recommended
to evaluate the effectiveness of the proposed changes comprehensively.
This research not only advances our understanding of how contract programming can be
seamlessly integrated into existing programming languages but also sets the stage for broader
applications of these concepts, potentially influencing software development practices across
various domains.