ByRef and ByVal in VBScript

后端 未结 6 2070
梦如初夏
梦如初夏 2020-11-28 08:24

I\'m facing something weird in VBScript. When writing a procedure where I want the parameter to be passed by reference, the way of calling this procedure changes the way the

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 08:39

    IncrementByRef Num
    

    calls and increments using a reference to Num

    IncrementByRef (47 + 3)
    

    calls and increments using a reference to "50". Which is discarded on exit.

    IncrementByRef (Num)
    IncrementByRef (Num + 18)*5
    IncrementByRef Cint("32")
    

    Are all legal in BASIC, as they were in FORTRAN. Notoriously, in one early FORTRAN, passing by ref allowed you to change the value of expressions like

    5
    

    Which was sufficiently confusing that only very small, early FORTRAN compilers had that kind of behaviour.

提交回复
热议问题