Mail Archives: djgpp/2004/07/27/16:00:06.1
On Mon, 26 Jul 2004 23:26:47 +1200 in comp.os.msdos.djgpp, Paul
Wilkins <disk AT paradise DOT net DOT nz> wrote:
>Paul Wilkins wrote:
>
>Do not post when tired.
>
>> Let's head back to the line where the trouble occurs, which I presume
>> you want to fix.
>>
>> m55:r--;if(R[r]!=1)goto m55;
>>
>> r gets decreased until R[r] = 1.
>>
>> That needs to be fixed so that r doesn't go below 0
><snip>
>> Is that right?
>>
>> In that case, let's count down to 0 and break out when we're successful.
>>
>> for (r; r>=0; r--) if (R[r]==0) break;
>
>Make that
> for (r; r>=0; r--) if (R[r]==1) break;
>
>>
>> or
>>
>> for (r; r>=0; r--)
>> if (R[r]==1)
>> break; // out of for loop
>
>If you don't want to check R[0] (ie. you use R[1] as your first entry)
>then change r>=0 to r>0 or r>=1
The posted code reminds me of Fortran programs I'd be handed by
engineers, while a junior programmer, to turn into a program usable by
others, or library routines that would play well with others.
The OP might be happier developing this type of (goto laden) code
under the g77 Fortran compiler, available from DJGPP mirrors, which
has the option -fbounds-check for subscript checking.
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian DOT Inglis AT CSi DOT com (Brian dot Inglis at SystematicSw dot ab dot ca)
fake address use address above to reply
- Raw text -