home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_07 / v7n7034a.txt < prev    next >
Text File  |  1989-09-04  |  1KB  |  48 lines

  1.  
  2. Listing 4
  3.  
  4. /*
  5.  * This program demonstrates the behavior of install when it
  6.  * tries to add a definition that is too big to fit in the
  7.  * table and the table ends near the end of a memory segment.
  8.  * This program has been compiled and tested with Microsoft C
  9.  * 5.1 using the compact, large and huge memory models.
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14.  
  15. #define MAXCHARS 65535
  16. #define ROOM 3
  17.  
  18. static char ndtable[MAXCHARS];
  19. static char *endtab = &ndtable[MAXCHARS];
  20. static char *nexttab = &ndtable[MAXCHARS - ROOM];
  21.  
  22. void install(const char *name, const char *defn)
  23.     {
  24.     size_t dlen, nlen;
  25.  
  26.     nlen = strlen(name) + 1;
  27.     dlen = strlen(defn) + 1;
  28.     if (nexttab + nlen + dlen > endtab)
  29.         printf("too many definitions");
  30.     else
  31.         {
  32.         printf("there's room!?");
  33.  
  34.         /* ... install the definition ... */
  35.  
  36.         }
  37.     printf(" (%p)\n", nexttab + nlen + dlen);
  38.     }
  39.  
  40. void main(void)
  41.     {
  42.     printf("ndtable = %p\n", ndtable);
  43.     printf("endtab  = %p\n", endtab);
  44.     printf("nexttab = %p\n", nexttab);
  45.     install("MAX", "100");
  46.     }
  47.  
  48.