Why do not use GOTO inside a Select Statement?

Just starting out? Need help? Post your questions and find answers here.
User avatar
useful
Enthusiast
Enthusiast
Posts: 404
Joined: Fri Jul 19, 2013 7:36 am

Re: Why do not use GOTO inside a Select Statement?

Post by useful »

Just a similar example.
This was discussed on the forum not too long ago. ( https://www.purebasic.fr/english/viewto ... 83#p586083 )

Code: Select all

Structure ArrayOfPointer
  *Index[0]
EndStructure

Procedure test(index)
  Protected *addr.ArrayOfPointer = ?jt 
  Protected result, *a
  
  DataSection : jt:
    Data.i ?l0 , ?l1 , ?l2 , ?l3 , ?l4
  EndDataSection 
  
  If (index < 5 ) And (index >= 0)
    
    CompilerIf #PB_Compiler_Backend = #PB_Backend_C  
      !goto *(void*)p_addr->f_index[v_index];
    CompilerElse 
      EnableASM  
      jmp *addr\Index[index]
      DisableASM 
    CompilerEndIf 
    
  Else 
    Goto le 
  EndIf  
  
  
  l0: 
  result =  0
  Goto lE 
  l1: 
  result = -1  
  Goto lE
  l2:
  result = -2  
  Goto lE 
  l3:
  result = -3 
  Goto lE 
  l4:
  result = -4  
  lE:
  
  ProcedureReturn result 
EndProcedure    


Debug test(3)
p.s. Let's simplify the compiler's life and create the transition table ourselves.
The compiler converts Select into approximately the same code
Dawn will come inevitably.
Post Reply