Select + Goto

Just starting out? Need help? Post your questions and find answers here.
Everything
Enthusiast
Enthusiast
Posts: 224
Joined: Sat Jul 07, 2018 6:50 pm

Select + Goto

Post by Everything »

Select + Goto inside always = Stack corruption.

Very basic example:

Code: Select all

Procedure test(val)
  Select val
    Case 1
      ;Do something
    Case 2
      ;Do something
    Default 
      Goto finalize
  EndSelect
  
  ;Do something else
  ProcedureReturn #True 
  
  finalize:
  ;cleanup
  ProcedureReturn #False 
EndProcedure

test(0)
I think this can be fixed.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Select + Goto

Post by Dude »

It's not a bug if the manual says not to do it:
Manual for 'Goto' wrote:never use it inside a Select/EndSelect block
;)
Everything
Enthusiast
Enthusiast
Posts: 224
Joined: Sat Jul 07, 2018 6:50 pm

Re: Select + Goto

Post by Everything »

True :)
never use it inside a Select/EndSelect block (Unless you have the ability to manage the stack yourself, correctly.)
Not a big deal to fix stack manually, or use alternatives. My bad, don't read the docs first, now I know, thx!
User avatar
Kiffi
Addict
Addict
Posts: 1357
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Select + Goto

Post by Kiffi »

Manual for 'Goto' wrote:never use it
;)
Hygge
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Select + Goto

Post by luis »

Manual for 'Goto' wrote:use it
;)
"Have you tried turning it off and on again ?"
A little PureBasic review
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Select + Goto

Post by User_Russian »

Code: Select all

Procedure test(val)
  Select val
    Case 1
      ;Do something
    Case 2
      ;Do something
    Default 
      FakeReturn
      Goto finalize
  EndSelect
  
  ;Do something else
  ProcedureReturn #True 
  
  finalize:
  ;cleanup
  ProcedureReturn #False 
EndProcedure

test(0)
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Select + Goto

Post by Josh »

User_Russian wrote:

Code: Select all

Procedure test(val)
  Select val
    Case 1
      ;Do something
    Case 2
      ;Do something
    Default 
      FakeReturn
      Goto finalize
  EndSelect
  
  ;Do something else
  ProcedureReturn #True 
  
  finalize:
  ;cleanup
  ProcedureReturn #False 
EndProcedure

test(0)
Good idea. I opened a request in Bugs/Documentation. Look here
sorry for my bad english
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Select + Goto

Post by Kwai chang caine »

@User-Russian
Waouuh !!
Thanks !! i have never see this command :shock:
Here is someone who use time for read the doc :oops:
ImageThe happiness is a road...
Not a destination
Post Reply