Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


UDSs and Global Variables

Keywords:  UDS global scope caller scope

Question:

; WinBatch 2002F #definesubroutine bug/feature

#definesubroutine BAR()
   message("BAR", strcat("In BAR G_VAR=", G_VAR))
#endsubroutine

#definesubroutine BAZ()
   message("BAZ", strcat("In BAZ, about to call BAR, G_VAR=", G_VAR))
   BAR()
#endsubroutine

#definefunction FOO()
   if (isdefined(G_VAR)) then
      message("FOO", strcat("In FOO, about to call BAR, G_VAR=", G_VAR))
   else
      message("FOO", "In FOO, about to call BAR, G_VAR is *UNDEFINED*")
   endif
   bar()
#endfunction

G_VAR = 42
; This works as expected since BAR() sees G_VAR in the caller's scope (the
; global scope in this case).
BAR()

; This works as expected since BAR() sees G_VAR in the BAZ()'s scope which
; received it from the global scope.
BAZ()

; This fails in 2002F.  It should work according to the doc which claims
; #definesubroutines handle variables as globals.  Instead it crashes because
; #definesubroutines really only take the caller's scope into consideration.
FOO()

Answer:

It's a feature. Documentation/description is incorrect.

#DefineSubroutine runs at the caller's scope, not global scope.