home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3053 < prev    next >
Encoding:
Text File  |  1991-03-15  |  1.3 KB  |  59 lines

  1. Newsgroups: comp.lang.c,alt.sources
  2. From: dm@think.com (Dave Mankins)
  3. Subject: Re: Small introspective program
  4. Message-ID: <1991Mar13.001423.5194@Think.COM>
  5. Date: Wed, 13 Mar 91 00:14:23 GMT
  6.  
  7.  
  8. This is not quite the same thing, but it is a hack I have found very useful
  9. when spinning small test programs.  
  10.  
  11. You start the program (e.g., ``foo.c'') with:
  12.  
  13. #ifdef notdef
  14.  
  15.   cc $0 -g -o `basename $0 .c` -Ineeded-includes -lneeded-libraries 
  16.  
  17.   exit;
  18.  
  19. #endif notdef
  20.  
  21. #include <stdio.h>
  22. ...
  23.  
  24. (all bound to an emacs function, insert-self-compile, of course)
  25.  
  26. Then invoke it with: 
  27.  
  28.     sh foo.c
  29.  
  30. This is much less labor-intensive than editing a Makefile (and re-editing it,
  31. if the source file should move to another directory).
  32.  
  33. Even in semi-formally maintained code, I have found this most useful in files
  34. that make up components of libraries, in this form:
  35.  
  36. #ifdef notdef
  37.  
  38.   cc $0 -DTEST -g -o `basename $0 .c` -Ineeded-includes -lneeded-libraries 
  39.  
  40.   exit;
  41.  
  42. #endif notdef
  43.  
  44.     /* library module source ... */
  45.  
  46. #ifdef TEST
  47.  
  48. main() {
  49.     .... code to test the call library functions with test inputs and 
  50.          check the results ....
  51. }
  52.  
  53. #endif /* TEST */
  54.  
  55. This allows your library modules to be self-testing, a great time-saver in the
  56. later phases of development.
  57. --
  58. david mankins (dm@think.com)
  59.