Lecture 1
Contents
PSA: A new compiler has entered the game
Okay not really, it’s the lecturer’s wrapper for clang
, which has pretty love messages (error messages in red) when things go wrong.
Compiling a single file
2521 3c -o prog prog.c
Compiling from multiple files
2521 3c -o prog prog.c f2.c f3.c
Compiling with leak checking
2521 3c +leak -o prog prog.c f2.c f3.c
Switch Statements
|
|
Equivalent to
|
|
The default case
|
|
Misc
- Function prototypes don’t need a variable name, only the type
break, continue, return
break
- exit a loopcontinue
- steps through the loop to the next iterationreturn
- exit a function (exits a loop implicitly)
function pointers
return_t (*var)(arg_t, …)
int -> int: int (*fp)(int);
(int, int) -> void: void(*fp2)(int,int);
When malloc
‘ing structs
If we’re using a pointer type, remember to pass in the actual struct to malloc
|
|
- Can’t dereference a typedef’d struct
#2
-sizeof(*st_ptr)
-> dereferencing during declaration to give usstruct st