March 29, 2019
For today:
1) Read HFC Chapter 8
2) Start Homework 7
3) Come to class with some Project 2 ideas (see here)
Today:
1) Homework 7
2) HFC Chapter 8
3) Project ideation
4) Exercise
For next time:
0) Finish the exercise
1) Finish Homework 7
2) Read Think OS Chapter 8 and do the reading quiz
3) Project 2 proposal
Optional: Watch Raymond Hettinger's PyCon talk about the implementation of dictionaries (hash tables) for Python.
Ways to implement polymorphic values:
1) Tagged union
Each object knows what kind of thing it is.
Every function that operates on objects has to check tags and dispatch.
Every object contains pointers to its methods.
Invoking a method means looking up a function and passing the object as a parameter.
Every object contains a pointer to its class.
Invoking a method means looking up a function in a class and passing the object as a parameter.
In Homework 7 the values in the hashtable are tagged unions; the keys are prototype-based objects.
Add a #include in your .c files AND add a -I flag on the compilation command line. AND don't forget the -l flag, AND sometimes the -L flag, too!
If you use the same libraries in many files, consider adding #include in your .h files, but in that case you should use include guards.
An archive file (.a) is a collection of object files (.o). The flag -lblah looks for an archive named libblah.a
Linking = looking up external names and resolving them.
Static linking: done at compile time.
Dynamic linking: done at load time.
Position-independent code has no absolute addresses, only relative.
dll = dynamically linked library
so = shared object code
dylib = dynamic library
Pros and cons of static and dynamic linking?
On Mac and Windows, the location of the DLLs is in the executable. In UNIX, LD_LIBRARY_PATH is an environment variable.
1) On your computer, take a look in /usr/include and /usr/local/include to see what header files you have.
2) Take a look in /usr/lib and /usr/local/lib to see what libraries you have. Which are statically linked? Which are dynamically linked?
In ExercisesInC/exercises/ex08, you should find a file called matrix.c that defines a structure to represent a matrix.
1) Read through the code to make sure you understand it. Draw a stack diagram that shows the state of the program when print_matrix_row runs for the first time. You can use C Tutor.
2) Compile and run it.
3) Fill in the body of reduce_matrix_rows and test it. If you are not familiar with row reduction, see https://en.wikipedia.org/wiki/Row_echelon_form
4) Notice that free_matrix doesn't do anything. Use Valgrind to confirm that this version leaks memory (recall that you have to compile with -g for Valgrind to work):
gcc -g -Wall matrix.c
valgrind --leak-check=yes ./a.out
5) Fill in free_matrix, then use Valgrind to confirm that you fixed the leak.