Midterm Review: What is going to be on midterm? - See list of topics on calendar Heres the list (shortened a bit to make concise): - Scope and Lifetime - Global vs local - Can globals be shared across files? Use 'extern' - Pass by ref vs pass by val - Example Q's - Midterm 2 Problem 1 - Midterm 3 Problem 7 - Midterm 4 Problem 1 (C) - Declaration vs. definition - The purpose of .h files - compiler only compiles one file at a time - Also to help the programmer use functions consistently - Don't forget about header guards! - Example Q's - Midterm 1 Problem 2 - Header guards - Midterm 2 Problem 4 - .h files - Midterm 2 Problem 6 - Declarations - Pointers - Example Q's - Midterm 1 Problem 5 - Pointer reasoning - Midterm 2 Problem 5 - Pointer reasoning, Structs - Midterm 3 Problem 1 - Pointers all over - Memory management - malloc, free, sizeof, checking if malloc returned NULL, stack overflow - Common Memory Bugs - Malloc wrong size - Didn't free - Didn't check if malloc failed - If error, didn't free before returning, (C++ has a fix for this) - Returning pointer to stack allocated mem - Example Q's - Midterm 3 Problem 2 - Find the bugs - Midterm 4 Problem 2 - Using valgrind - C strings - Static string - char p[] = "house"; vs char *p = "house"; - first one copies, second one is a reference to read-only memory - second one resides in read only segment in memory - writing to them is undefined - Must end string with '\0' - Example Q's - Midterm 1 Problem 4 - C string semantics - Midterm 1 Problem 6 - C string semantics - The preprocessor -#include, #define, #ifndef - Example Q's - Midterm 2 Problem 7 - Macros - gcc compilation flow (preprocessing, compiling, linking) - Example Q's - Midterm 4 Problem 1 (B) - linking - basic string functions (strncpy, strncmp) - Function pointers - example typedef int (*IntFunc)(int x); - Example Q's - Midterm 3 Problem 1 - Used function pointers - Generics in C - void* vs. customized code generation (at compile time) - callbacks - Example Q's - Midterm 1 Problem 7 - generic stack - Midterm 3 Problem 5 - generic binary tree - Files - buffered vs. unbuffered I/O - buffered: - Read/write data in a userspace buffer in large chunks - pros: faster - unbuffered - Read/write data byte by byte from device driver - pros: data is more consistent ie not "stale", data is not easily lost - open, write, read - Example Q's - Midterm 4 Problem 5 - Object-oriented programming style in C - “classes”, “inheritance” - dynamic dispatch / vtables - jansson / gtk+ reference counting (?? Maybe) - Projects 1-3 Object-oriented programming style in C: - Dog example code - when you say (in Java) myObj.foo() you invoke the foo() defined by myObj's class, or its closest ancestor class if it doesn't define foo() itself. Which parameters can be changed inside of sub?? char * sub(void *one, int two, int *three, char **four);