BBC BASIC for Windows
Programming >> BBC BASIC language >> Procs within Proc's
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1235948869
Procs within Proc's
Post by MALCOLM on Mar 1st, 2009, 10:07pm
I didn't get an answer to the exact case I was asking.
Is this a valid construction. I am not sure that I (or anyone) need it but...
DEF PROCa
...
DEF PROCb .......:ENDPROC
...
ENDPROC
Malcolm.
Re: Procs within Proc's
Post by Malcolm on Mar 2nd, 2009, 04:41am
Thinking about this and following the other thread I see that it is only the DEF part that gets registered as a start of a Procedure and therefore an address to jump to. The code continues until an ENDPROC and returns. So I can answer myself that it sees this just as two PROCs with no knowledge of their relationship one within the other.
Malcolm.
Re: Procs within Proc's
Post by JonR on Mar 15th, 2009, 7:04pm
Yes that is a valid construction but of limited usefulness in the manner described. When called PROCa will be executed normally, the interpreter will treat the line beginning DEF as though it was a comment and continue executing PROCa. When you call PROCb the interpreter executes it as normal and exit at the ENDPROC.
If the ENDPROC for PROCb was conditional and execution fell through to the next line the interpreter would keep executing up to the ENDPROC associated with PROCa unless the code failed with an error.
If you find yourself writing code like that it is worth looking for a more elegant solution.
Re: Procs within Proc's
Post by Malcolm on Mar 16th, 2009, 12:37am
Thanks, Jon.
I agree with your sentiments.