A look at type systems
What is a type in the context of a programming language?
int
, long long
, int*
etc.int
, long long
, int*
etc.42
is an integer literal and has type int
int
, long long
, int*
etc.42
is an integer literal and has type int
int(int)
, int()
int
, short
, char*
etc."hello" * 2
)const
)x86-64
assembly code:
x86-64
assembly code:
div(2, 0)
might crash the programdiv(3.0, 2.0)
? What would be a reasonable assumption?x86-64
assembler, C++ and Python don’t help us here!NonZeroI32::new(0)
?
NonZeroI32
from scratchLive example
NonZeroI32
new
function for creating instances)div
requires a non-zero second argument!Into
NonZeroI32
zero-cost?