Mail Archives: djgpp/2004/07/27/16:15:15
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 -