#ifndef _UTILITY_H #define _UTILITY_H /* utility.h * coded by Alex Gruenstein for CS107, TA: AndyG * This is the interface to a useful memory allocation * function (GetBlock) and a useful macro (New) */ /* macro: New(type) * This is a macro written by Eric Roberts for cs106 that * simplifies memory allocation. It is used to * allocate memory for a given type (eg a struct). * usage: struct myStruct *m = New(struct myStruct) */ #define New(type) ((type) GetBlock(sizeof *((type) NULL))) /* function: GetBlock * this is a modified version of the function developed * by Eric Roberts for cs106. It is an error checking * wrapper for malloc(). It ensures that the memory * could be allocated, and if not it halts the program * via the assert macro. * it returns a pointer to free blcok of memory in the heap * of a given size (in bytes) */ void *GetBlock(unsigned int size); /* function: CopyString * this is a utility function supplied by cs107 that I have * modified slightly. * it places a copy of a string in memory that it allocates * on the heap * returns: a pointer to the new string */ char *CopyString(const char *s); #endif