Page 1 of 1

add Labels(Labels) for Labels with Global

Posted: Fri Apr 07, 2017 12:52 pm
by gurj
add Labels(Labels) for Labels with Global

Code: Select all

Procedure dd()
Labels(re)
EndProcedure
dd();will Goto re
re:

Re: add Labels(Labels) for Labels with Global

Posted: Fri Apr 07, 2017 8:42 pm
by GPI
very bad idea, because the "Programm/CPU" thinks, that it is still in the Procedure and will don't clean up thinks like the stack.

Re: add Labels(Labels) for Labels with Global

Posted: Fri Apr 07, 2017 8:58 pm
by Demivec
If the code will execute in a procedure without using the stack for variables then it will execute outside the procedure too. So put the subroutine in the main scope instead.

I give this a no vote (-1).

Re: add Labels(Labels) for Labels with Global

Posted: Wed Apr 19, 2017 2:53 pm
by gurj
ok:

Code: Select all

ppp=8
Prototype ABCD()
t=?AddBCD
Global AddBCD.ABCD = t

;AddBCD()

Procedure dd()
AddBCD()
EndProcedure
dd()

End

AddBCD:
Debug ppp

Re: add Labels(Labels) for Labels with Global

Posted: Mon Apr 24, 2017 8:05 am
by GPI
@gurj
let's extend your example a little bit:

Code: Select all

ppp=8
Prototype ABCD()
t=?AddBCD
Global AddBCD.ABCD = t

;AddBCD()

Procedure dd()
AddBCD()
EndProcedure
dd()

Debug "end"
End

AddBCD:
Debug ppp
Debug "end Addbcd"

will result in:

Code: Select all

8
end Addbcd
The Problem: With callig "AddBCD()" in dd() you call a function - but the function never returns!

Your example is the perfect reason, why global Labels are forbidden. With your code, your Programm exit with a currupt Stack. Using this kind of programming style will cause very hard to detect Bugs and crashes.

In my opinion gosub is outdated. There is not one reason, why someone should use gosub instead of Procedures. And in 99% goto is primary a bad programming style. When you want for example exit a loop, simple use the "exit" command.

Re: add Labels(Labels) for Labels with Global

Posted: Mon Apr 24, 2017 1:42 pm
by gurj
thanks GPI !