Hi folks,
A few days ago I spent a bit of time searching for a bug in a program. I found the bug, but I'm not sure exactly what is going on. The code below demonstrates the bug I created:
Code:
PRINT "Test 1 - The following output is as intended:"
PROC_test1
PRINT "Press ANY KEY to see output from Test 2"
K% = GET
PROC_test2
END
DEF PROC_test1
LOCAL I%, J%
I% = 10
WHILE I%
J% = FN_getValue(I%)
PROC_print(J%)
ENDWHILE
ENDPROC
DEF PROC_test2
LOCAL I%
I% = 10
WHILE I%
PROC_print(FN_getValue(I%))
ENDWHILE
ENDPROC
DEF PROC_print(I%)
PRINT I%
ENDPROC
DEF FN_getValue(RETURN P%)
LOCAL I%
I% = P% * 2
P% -= 1
=I%
In this example, PROC_print() and FN_getValue() are analogous to routines that were INSTALLed from a library, and so my main program did not 'know' their implementation. I would have expected PROC_test2 to function exactly the same as PROC_test1. What do I need to understand to be able to foresee situations like this again?
Thanks very much
Andy