Listing 4 /* * This program demonstrates the behavior of install when it * tries to add a definition that is too big to fit in the * table and the table ends near the end of a memory segment. * This program has been compiled and tested with Microsoft C * 5.1 using the compact, large and huge memory models. */ #include #include #define MAXCHARS 65535 #define ROOM 3 static char ndtable[MAXCHARS]; static char *endtab = &ndtable[MAXCHARS]; static char *nexttab = &ndtable[MAXCHARS - ROOM]; void install(const char *name, const char *defn) { size_t dlen, nlen; nlen = strlen(name) + 1; dlen = strlen(defn) + 1; if (nexttab + nlen + dlen > endtab) printf("too many definitions"); else { printf("there's room!?"); /* ... install the definition ... */ } printf(" (%p)\n", nexttab + nlen + dlen); } void main(void) { printf("ndtable = %p\n", ndtable); printf("endtab = %p\n", endtab); printf("nexttab = %p\n", nexttab); install("MAX", "100"); }