teaching machines

CS 330 Lecture 18 – Types

March 10, 2016 by . Filed under cs330, lectures, spring 2016.

Agenda

TODO

Note

Let’s start with a Fill in the Blank…

Types are like…

A primary advantage of high-level languages over assembly is a type system. In short, we can define a type as a designation of the following:

Types serve as annotations or clues to the compiler. By providing a type, you give the compiler some information that it can use to verify that you’re doing legal things with your data.

Types do not necessarily appear in the machine code, but certainly influence which instructions are generated and what sizes and offsets are used to index memory.

We’ll look at how a language’s type system is classified in the following spectra: explicit vs. implicit, static vs. dynamic, strong vs. weak.

Then we’ll write some examples in C that conform to or violate the type system. Our first exercise will be a Program This:

Implement atoi(const char *s), which turns a C string into an int. Assume s is comprised only of digits and doesn’t exceed the capacity of an int.

Code

atoi.c

/usr/lib/ruby/2.7.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'coderay' (>= 0) among 56 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/.gem/ruby/2.7.0:/var/lib/gems/2.7.0:/usr/lib/ruby/gems/2.7.0:/usr/share/rubygems-integration/2.7.0:/usr/share/rubygems-integration/all:/usr/lib/x86_64-linux-gnu/rubygems-integration/2.7.0:/home/johnch/.gems', execute `gem env` for more information
	from /usr/lib/ruby/2.7.0/rubygems/dependency.rb:323:in `to_spec'
	from /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_gem.rb:62:in `gem'
	from ./coderay:24:in `
'