1+ [ CPROVER Manual TOC] ( ../../ )
2+
13# Function Contracts
24
35CBMC offers support for function contracts, which includes three basic clauses:
@@ -56,9 +58,9 @@ A function contract has three parts:
5658In our example, the developer may require from the caller to properly allocate
5759all arguments, thus, pointers must be valid. We can specify the preconditions of
5860a function using `__CPROVER_requires` (see [Requires \& Ensures
59- Clauses](contracts- requires-and-ensures.md) Section for details) and we can
61+ Clauses](../../ contracts/ requires-and-ensures/) for details) and we can
6062specify an allocated object using a predicate called `__CPROVER_is_fresh` (see
61- [Memory Predicate](contracts- memory-predicates.md) Section for details). Thus, for the `sum` function, the set
63+ [Memory Predicate](../../ contracts/ memory-predicates/) for details). Thus, for the `sum` function, the set
6264of preconditions are
6365
6466```c
@@ -67,15 +69,15 @@ __CPROVER_requires(__CPROVER_is_fresh(out, sizeof(*out)))
6769```
6870
6971We can use ` __CPROVER_ensures ` to specify postconditions (see [ Requires \&
70- Ensures Clauses] ( contracts- requires-and-ensures.md ) Section for details). In our
72+ Ensures Clauses] ( ../../ contracts/ requires-and-ensures/ ) for details). In our
7173example, developers can use the built-in construct ` __CPROVER_return_value ` ,
7274which represents the return value of a function. As postconditions, one may list
7375possible return values (in this case, either ` SUCCESS ` or ` FAILURE ` ) as well as
7476describe the main property of this function: if the function returns ` SUCCESS ` ,
7577then ` *out ` stores the result of ` a + b ` . We can also check that the value in
7678` *out ` will be preserved in case of failure by using ` __CPROVER_old ` , which
7779refers to the value of a given object in the pre-state of a function (see
78- [ History Variables] ( contracts- history-variables.md ) Section for details). Thus, for the ` sum ` function, the
80+ [ History Variables] ( ../../ contracts/ history-variables/ ) for details). Thus, for the ` sum ` function, the
7981set of postconditions are
8082
8183
@@ -87,7 +89,7 @@ __CPROVER_ensures((__CPROVER_return_value == FAILURE) ==> (*out == __CPROVER_old
8789```
8890
8991Finally, the _assigns_ clause allows developers to define a frame condition (see
90- [Assigns Clause](contracts- assigns.md) Section for details).
92+ [Assigns Clause](../../ contracts/ assigns/) for details).
9193In general, systems for describing the frame condition of a function
9294use either writes or modifies semantics; this design is based on the former.
9395This means that memory not specified by the assigns clause must
@@ -149,8 +151,8 @@ program using contracts.
149151
150152## Additional Resources
151153
152- - [ Requires \& Ensures Clauses] ( contracts- requires-and-ensures.md )
153- - [ Assigns Clause] ( contracts- assigns.md )
154- - [ Memory Predicates] ( contracts- memory-predicates.md )
155- - [ History Variables] ( contracts- history-variables.md )
156- - [ Quantifiers] ( contracts- quantifiers.md )
154+ - [ Requires \& Ensures Clauses] ( ../../ contracts/ requires-and-ensures/ )
155+ - [ Assigns Clause] ( ../../ contracts/ assigns/ )
156+ - [ Memory Predicates] ( ../../ contracts/ memory-predicates/ )
157+ - [ History Variables] ( ../../ contracts/ history-variables/ )
158+ - [ Quantifiers] ( ../../ contracts/ quantifiers/ )
0 commit comments