/* File: lists.h Author: James Mayfield This file provides access to the standard linked list routines developed in CMSC 202. To use it: 1. Typedef the type `list_item_type' in your program. List_item_type MUST BE NO LARGER THAN A POINTER TYPE! (So it's OK to use `int' for list_item_type, but not an array or a struct). You can put a call to check_list_item_size() at the top of your main program to make sure your list_item_type is of an appropriate size. 2. #include "lists.h" AFTER your definition of list_item_type. 3. Compile your program so that it uses the 202 libraries. To do so, you will need add several items to your Makefile. Lines of the Makefile that create .o files will need to include `-I ~mayfield/lib202' immediately after the cc command, e.g.: cc -I ~mayfield/lib202 -g -c myfile.c Lines of the makefile that build executables will need to include `-L ~mayfield/lib202 -l202' immediately after the list of .o files, e.g.: cc -o myprog myfile.o myfile_aux.o -L ~mayfield/lib202 -l202 */ #ifndef _CMSC_202_LISTS_ #define _CMSC_202_LISTS_ /* For check_list_item_size: */ #include #include #include "basics.h" typedef struct list_tag *list_type; #define the_empty_list NULL list_type cons(list_item_type value, list_type list); list_item_type first(list_type list); list_type rest(list_type list); BOOL empty_list(list_type list); #define check_list_item_size() do { if (sizeof(list_item_type) > sizeof(void *)) { \ fprintf(stderr, "List error: list_item_type is larger than a pointer.\n"); \ exit(EXIT_FAILURE); \ }} while (0) #endif