From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10f8a1,e7e13c943c611b62 X-Google-Attributes: gid10f8a1,public X-Google-Thread: 102b75,be3d6a6131c61fa7 X-Google-Attributes: gid102b75,public X-Google-Thread: 1164f8,be3d6a6131c61fa7 X-Google-Attributes: gid1164f8,public From: ttk@for_mail_remove_this_and_fruit.larva.apple.shinma.org (TTK Ciar) Subject: Re: Did Intel pay UGS to kill Alpha port? Or Compaq simply doesn't care? Date: 1999/04/14 Message-ID: <924104079.471.70@news.remarQ.com>#1/1 X-Deja-AN: 466330084 References: <36E9F2A0.9A401A09@pacific.net.sg> <7eih45$ln2$1@news.doit.wisc.edu> X-Complaints-To: newsabuse@remarQ.com X-Trace: 924104079.471.70 X59QMCGAS1102CDB3C usenet1.supernews.com Organization: Subtle, but there NNTP-Posting-Date: Wed, 14 Apr 1999 15:34:39 GMT Newsgroups: comp.arch,comp.sys.dec,vmsnet.alpha In article , Maynard Handley wrote: > >Am I the only person in the world who writes every single damn function he >types up as > >#if DEBUG > #define FLAG_ERROR(error) if(error!=noErr) Debugger() >#else > #define FLAG_ERROR(error) >#endif > > error=CallSomeFunc(...); > FLAG_ERROR(error); > >I have never seen any other code that does this, yet the pain it saves is >immeasurable. Regardless of whether or not I can do anything useful >subsequently with the error, the very fact that I catch the problem in the >debugger at the source, not 50 corrupted memory blocks later is >extraordinarily useful. Sometimes I'll do this (or some subset or variation on it): #define DB_FOO 1 #define DB_BAR 2 #define DB_BAZ 4 static int ErrResult = 0; static long Iteratung = 0; #define DEBUG ( DB_FOO | DB_BAZ ) #define DB(X) if ( DEBUG & X ) #define DBWRAP(F) \ if ( ( Iteratung++ | 1 ) && \ ( ErrResult = F ) < 0 ) \ if ( DEBUG ) Dump ( Iteratung, ErrResult ) int some_function ( key ) int key; { ... } int baz_function ( p ) char *p; { DB(DB_BAZ) if ( p == NULL ) return -1; DB(DB_BAZ) if ( p[0] == 0 ) fprintf ( stderr, "baz_function: passed zero-length arg\n" ); ... } int some_other_function ( blech ) struct blecht *blech; { int key; DBWRAP ( key = baz_function ( blech->str ) ); DBWRAP ( some_function ( key ) ); ... } And then I'll juggle DEBUG's definition depending on which part of the code I'm interested in debugging at the time. When it's the sort of application gdb can handle elegantly, though, I'll often eschew with this kind of annotation and just use gdb. Having better debugging support in the language for making this sort of thing easier would be good, but I've not liked any such implementation I've seen. I've been using gcc with the bounds- checking mod lately; it does a good job at catching some errors at run-time and dumping debugging information without my having to explicitly code for it at all. -- TTK