home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!not-for-mail
- From: avg@rodan.UU.NET (Vadim Antonov)
- Newsgroups: comp.programming
- Subject: Re: Help - What Is Wrong?
- Date: 11 Nov 1992 16:04:17 -0500
- Organization: Berkeley Software Design
- Lines: 45
- Message-ID: <1drsghINN9la@rodan.UU.NET>
- References: <1992Nov9.154402.16285@hubcap.clemson.edu> <1992Nov10.135848.3730@jyu.fi> <1992Nov11.194809.18616@hubcap.clemson.edu>
- NNTP-Posting-Host: rodan.uu.net
-
- Well, both advices (i.e. to have strict guards in loops instead of
- weak ones and to use if-s covering all cases) should be taken with
- a LARGE grain of salt.
-
- First of all, never write for( x = 0.0 ; x != 1.0 ; x += 0.1 ) ...
-
- Then, use assert-s.
-
- Instead of relying on infinite loops (and given modern CPUs
- 32-bit "infinite loop" may be under a second) which can
- pass unnoticed (or worse...) you may write
-
- assert(i <= n);
- for( ; i < n ; i++ )
- ....
-
- In case of ifs
-
- if( cond1 ) {
- ...
- } else if( cond2 ) {
- ...
- } else {
- assert(cond3);
- ...
- }
-
- will do essentially the same thing as suggested
-
- if( cond1 ) {
- ...
- } else if( cond2 ) {
- ...
- } else if( cond3 ) {
- ...
- } else
- abort();
-
- but will print out additional information making the search easier
- (it's especially useful if the stack was trashed so debugger can't
- reconstruct the sequence of calls) and the program can be later
- recompiled with null assert-s to eliminate the performance penalty
- for extra checks.
-
- --vadim
-