Chapter 5: Basic Values & Data
Level 1 — Acquaintance
The foundation of all computation: types, values, and how C and Auto represent data.
This is the most important chapter in Level 1. Everything you build in C or Auto rests on understanding how the language represents values in memory. We cover the abstract machine model, basic types, conversions, initializers, named constants, and binary representations.
5.1 The Abstract State Machine
C Deep Dive: The C standard does not describe a physical computer. Instead it defines an abstract state machine that specifies what a conforming program must do. A real compiler's job is to produce code that behaves as if the abstract machine executed the program.
The abstract machine has:
- Objects — regions of storage that hold values (variables, allocated memory).
- Values — the bit patterns stored in objects, interpreted according to their type.
- Side effects — changes to the state of the machine (writing to a variable, calling an I/O function).
- Sequence points — moments when all preceding side effects are guaranteed complete.
When you write int x = 42;, the abstract machine:
- Allocates storage for an object named
x. - Determines that its type is
int. - Stores the value
42in that object.
Auto simplifies this model by removing undefined behavior. If an Auto program compiles, it has well-defined semantics. The trade-off is that Auto hides certain machine-level details that C exposes (such as raw pointer arithmetic and exact object layout).
Takeaway: C's abstract machine is a contract between you and the compiler. Stay within the contract and your code is portable and predictable. Violate it (e.g., via undefined behavior) and the compiler is free to do anything.
5.2 Basic Types
C has a small but nuanced set of fundamental types. Auto maps them to a cleaner subset:
| C type | Auto type | Size (typical) | Notes |
|---|---|---|---|
char | char | 1 byte | Character or small integer |
signed char | i8 | 1 byte | Explicitly signed 8-bit |
unsigned char | u8 | 1 byte | Unsigned 8-bit |
short | i16 | 2 bytes | Short integer |
int | int | 4 bytes | Default integer |
long | i64 | 4 or 8 bytes | Platform-dependent |
long long | i64 | 8 bytes | At least 64-bit |
float | float | 4 bytes | Single-precision IEEE 754 |
double | float | 8 bytes | Double-precision; Auto uses float for both |
_Bool | bool | 1 byte | C99 boolean; Auto has bool |
size_t | usize | 4 or 8 bytes | Unsigned, sizeof result |
Key differences:
- C's
doubleis distinct fromfloat. Auto unifies them asfloatand lets the compiler choose the precision. - C has signed/unsigned variants for every integer type. Auto defaults to signed and provides explicit
u8,u16,u32,u64for unsigned needs. - C's
charmay be signed or unsigned depending on the platform. Auto treatscharas a distinct type for character data only.