home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,alt.sources
- From: dm@think.com (Dave Mankins)
- Subject: Re: Small introspective program
- Message-ID: <1991Mar13.001423.5194@Think.COM>
- Date: Wed, 13 Mar 91 00:14:23 GMT
-
-
- This is not quite the same thing, but it is a hack I have found very useful
- when spinning small test programs.
-
- You start the program (e.g., ``foo.c'') with:
-
- #ifdef notdef
-
- cc $0 -g -o `basename $0 .c` -Ineeded-includes -lneeded-libraries
-
- exit;
-
- #endif notdef
-
- #include <stdio.h>
- ...
-
- (all bound to an emacs function, insert-self-compile, of course)
-
- Then invoke it with:
-
- sh foo.c
-
- This is much less labor-intensive than editing a Makefile (and re-editing it,
- if the source file should move to another directory).
-
- Even in semi-formally maintained code, I have found this most useful in files
- that make up components of libraries, in this form:
-
- #ifdef notdef
-
- cc $0 -DTEST -g -o `basename $0 .c` -Ineeded-includes -lneeded-libraries
-
- exit;
-
- #endif notdef
-
- /* library module source ... */
-
- #ifdef TEST
-
- main() {
- .... code to test the call library functions with test inputs and
- check the results ....
- }
-
- #endif /* TEST */
-
- This allows your library modules to be self-testing, a great time-saver in the
- later phases of development.
- --
- david mankins (dm@think.com)
-