Xref: utzoo comp.lang.c:37002 alt.sources:3466 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!think.com!dm From: dm@think.com (Dave Mankins) Newsgroups: comp.lang.c,alt.sources Subject: Re: Small introspective program Message-ID: <1991Mar13.001423.5194@Think.COM> Date: 13 Mar 91 00:14:23 GMT References: <1991Mar10.231230.1301@casbah.acns.nwu.edu> <1991Mar12.050929.2870@research.canon.oz.au> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge, Massachusetts Lines: 52 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 ... (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)