cint

cint university / ced, the cint editor

cint for C programmers

This page is part of CU-000.2, checked against cint 0.2.0.

Read this before 201 if you know C. It lists what carries over, what changes and the lesson that shows each change running.

what carries over

Much of cint reads like C. Functions are declared with the return type first, statements end with a semicolon and blocks are in braces. if, else, while, break, continue and return keep their meaning, and so does the C form of for. switch looks the same and differs in the ways listed below. Comments are written with //. Integer types say their width in the name: I8 to I1024 are signed and U8 to U512 are unsigned. I32 is C's int32_t and U8 is uint8_t. cint compiles a program to C17, and 201-00 shows the C it makes.

what changes

In C In cint Shown in
Signed overflow is undefined behavior. Every plain operator is checked. A result that does not fit stops the program with a fault that names the operation, the operands and the exact result. 201-01
Unsigned arithmetic wraps without a sign of it. Plain unsigned operators are checked too. Wrapping is written as an operator of its own, such as +%, and saturating as +|. 201-03
A shift by the width of the type or more is undefined. A shift that loses bits faults. 201-03
Integer promotion and implicit conversions happen everywhere. No conversion happens on its own, not even to a wider type. as converts and faults if the value does not fit. as% keeps the low bits and as? hands the failure to the program. 201-02
/ rounds toward zero, and % takes the sign of the dividend. / rounds toward negative infinity, and % takes the sign of the divisor, as in Python. div_trunc and rem_trunc give C's results. 201-04
A rounding rule is set somewhere else, or implied. Each rounded division names its rule, such as div_round(a, b, half_even). 201-04
An array index is not checked. Every index is checked, and one past the end faults with E_BOUNDS. 101-12
A function takes a pointer and a length. A function takes a view of an array, in I64[n] to read it or inout I64[n] to change it, and the length travels with it. 201-07, 201-09
A deep recursion can crash when the stack runs out, unless the compiler turns it into a loop. The depth depends on the machine. At most 256 calls can be in progress at once, counting main, and one more faults with E_DEPTH on every machine. 201-09
A case without break falls into the next. A case ends at the next case. Falling through is written as fallthrough;. 201-08
if (x = 5) assigns and tests. An assignment is a statement, so this is error C1041. 201-08
Braces around a body of one statement are optional. Every body needs its braces. 201-08
i++ is an expression with a value. i++ is a statement, and it is checked. 201-08
C uses #include and #define. There is no preprocessor. const names a constant. 401-02
C has float and double. There is no floating-point type. Every value in these courses is an integer.

the same program on every compiler

A C program that overflows can print one thing at -O0 and another at -O2, and 301-01 shows one doing exactly that. A cint program prints the same bytes on GCC, Clang, MSVC and Apple Clang. When it faults, it prints the same fault record on each of them, field for field. So one saved output checks a run on any of those compilers, as 201-05 shows.

where to start

Start with 201-00. It sets up cint and shows the four commands and the C that a small program becomes.