add Labels(Labels) for Labels with Global

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

add Labels(Labels) for Labels with Global

Post by gurj »

add Labels(Labels) for Labels with Global

Code: Select all

Procedure dd()
Labels(re)
EndProcedure
dd();will Goto re
re:
my pb for chinese:
http://ataorj.ys168.com
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: add Labels(Labels) for Labels with Global

Post 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.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: add Labels(Labels) for Labels with Global

Post 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).
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: add Labels(Labels) for Labels with Global

Post 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
my pb for chinese:
http://ataorj.ys168.com
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: add Labels(Labels) for Labels with Global

Post 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.
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: add Labels(Labels) for Labels with Global

Post by gurj »

thanks GPI !
my pb for chinese:
http://ataorj.ys168.com
Post Reply