Path: utzoo!censor!geac!torsqnt!hybrid!scifi!bywater!uunet!overload!dillon From: dillon@overload.Berkeley.CA.US (Matthew Dillon) Newsgroups: comp.sys.amiga.programmer Subject: Re: Good Programming stops guru |||| and BNF of C++ Message-ID: Date: 14 Jan 91 02:03:02 GMT References: <1806@winnie.fit.edu> <658@tnc.UUCP> <1991Jan11.073543.16293@zorch.SF-Bay.ORG> Organization: Not an Organization Lines: 67 In article <1991Jan11.073543.16293@zorch.SF-Bay.ORG> mykes@zorch.SF-Bay.ORG (Mike Schwartz) writes: >I use Manx 'C' 3.6, so my advise may be limited to this environment. > >Manx supplies a routine called _abort() in the library which can be Under ANSI C you can use atexit(). This will be MUCH more portable then _abort() which is MANX specific. main() { atexit(myexitrt); ... } myexirt() is called when the program exits, whether it be a normal exit or an abnormal exit. >The code for panic shows how (using 32-bit INT model of Manx) you can >make a printf() like routine without a lot of ugly looking code. The >drawback is that you are pushing a lot of parameters in a lot of places. Additionally, under ANSI C, there are var-args printing calls, vprintf(), vsprintf(), and vfprintf(). These make it easy to write your own error-printing routines without having to hack large variable lists: /* * Example use var-args [v]*printf() orutines * get the math pfmt. */ #include #include void gagprint(char *, ...); main() { gagprint("%d %d %d\n", 1, 2, 3); return(0); } void gagprint(ctl, ...) char *ctl; { va_list va; int n; va_start(va, ctl); n = vprintf(ctl, va); printf("%d chars written\n", n); va_end(va); } > >Mykes -- -Matt Matthew Dillon dillon@Overload.Berkeley.CA.US 891 Regal Rd. uunet.uu.net!overload!dillon Berkeley, Ca. 94708 USA