delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/07/27/16:15:15

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Cesar Rabak <crabak AT acm DOT org>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: assembly code of the "strange error" - program
Date: Tue, 27 Jul 2004 17:04:38 -0300
Lines: 56
Message-ID: <4106B556.9010503@acm.org>
References: <WcpNc.640$zS6 DOT 86489 AT news02 DOT tsnz DOT net> <20040727070949 DOT 29244 DOT 00000306 AT mb-m19 DOT aol DOT com>
Mime-Version: 1.0
X-Trace: news.uni-berlin.de sVr9Zhime53I3H9Th0qxpweCY93sjszwWnvieKnsXSLmyaEFg=
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-BR; rv:1.0.2) Gecko/20030208 Netscape/7.02
X-Accept-Language: pt-br, pt
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Sterten escreveu:
> Paul Wilkins wrote:
> 
>  >R[r] is looping with the r index being reduced by one each time, so the 
>  >program is accessing R[3], R[2], R[1], R[0], and then on to R[-1], 
>  >R[-2], etc..
> 
> yes
> 
>  >Most people will now be feeling a sense of horror, at seeing negative 
>  >array indexes, because arrays ARE NOT supposed to have negative indicies.
> 
> and that should be reason enough for a good compiler to issue a runtime
> warning at this point. The reason why gcc doesn't do this is mere
> program-speed, I assume. But this warning/error suppressing
> could also be put into one of the optimising switches "-Ox"  IMO.
> 

Guenter,

As the issue of how hard is for the compiler to work this out has been 
discussed already in the post, let's see how a language construct can 
help you here:

instead of (plainly):

m55:r--;if(R[r]!=1)goto m55;

do this:

#include <assert.h>
.
.
.
m55: r--;
assert( r > 0 );
if(R[r]!=1)
	goto m55;
.
.
.

Now your program will abort if the condition above "(r > 0)" is violated 
and will give you a nice report on where in you program this ocurred.

For further details, check the library documentationą:

C:\info libc alph assert

HTH

--
Cesar Rabak

[1] You *have* the documentation and info reader installed, haven't you?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019