CSE 15 Lecture Notes - Lecture 7: C String Handling, Test Harness, C Dynamic Memory Allocation
Document Summary
#ifndef (if not defined) _bvector you put a guard around it to get rid of duplicate function calls. # include need it for malloc/int static inline bitv *newvec(uint32_t l) inline function = compiler doesn"t call function, takes what"s in function and inserts directly in the code. Macros have call-by-name semantics, in-line have normal call-by-value semantics. Has to be declared static. bitv *v = (bitv *) malloc(sizeof(sizeof(bitv)); allocate bucket, then water malloc returns void * if (v) # define setbit(x, k) x->v[k. 8] |= (0x1 << k%8) 0x1 = octal. # define clrbit(x, k) x->v[k. 8] &= ~(0x1 << k%8) # define valbit(x, k) ((x->v[k. 8] & (0x1 << k%8)) != 0) Malloc v calloc: malloc allocates things in bytes (doesn"t initialize bytes, calloc allocates things you specify. Why we did bitvectors: for the next assignment, you"re going to need a set, you need to select which sort you want to run, subset, set.