Reference C0.4
t [ ] For any type t, we can form the type t[ ], the type of arrays of values
of type t. A value of this type is a reference to an array stored in
memory. An array A has an intrinsic length n determined at the type
of allocation; its elements can be referenced as A[0] through A[n − 1].
t
*
For any type t, we can form the type t
*
, the type of pointers to values of
type t stored in memory. Its values are addresses and a special value
NULL.
struct s Structs are aggregates whose members can be accessed through
field names. The fields and their types for each structure named s
have to be explicitly declared. Structures are allocated in memory.
Unlike the elements of other types, structures cannot be assigned to
variables or passed as function arguments because they can have ar-
bitrary size. Instead, we pass pointers to structs or arrays of structs.
Functions and commands There are no explicit types for functions and
commands, because the language does not allow them to be passed as
arguments or stored explicitly. Of course, the language has means to
define and invoke functions, and execute commands including vari-
able assignments, conditionals and loops.
Contracts Again, there is no explicit type for contracts, but C0 supports
contracts governing the permissible invocations, return values, and
effects of functions. Currently, they can only be checked dynamically,
although some tools for static checking are under development.
3 Integers
The type of integers is int. The values are 32-bit words, interpreted accord-
ing to two’s complement arithmetic. This means arithmetic is modulo 2
32
,
with the minimal representable integer being −2
31
= −2147483648 and the
maximal being 2
31
− 1 = 2147483647. Decimal constants c in a program
must be in the range 0 ≤ c ≤ 2
31
, where 2
31
= −2
31
according to modular
arithmetic. Hexadecimal constants must fit into 32 bits.
Integer operations are the usual binary + (addition), - (subtraction),
*
(multiplication), which operate modulo 2
32
. In addition we have integer
division n/k and modulus n%k. Division truncates towards zero, and both
division and modulus raise an overflow exception if k = 0 or n = −2
31
and
k = −1. If n is negative, the result of the modulus will be negative, so that
(n/k)
*
k + n%k == n when the left-hand side doesn’t overflow.
15-122 FALL 2020 MONDAY 18
TH
JANUARY, 2021