For example, is there a price for the following self-documenting expression?
Code: Select all
case asc("0")
Code: Select all
case asc("0")
Unless you turn off optimization (which is on by default) the compiler will detect compile-time constant value expressions (including those involving ZBasic System Library functions) and substitute the constant value. Consider this simple example:GTBecker wrote:Is an expression that will always yield a constant evaluated at run time or it is equivalent to a constant?
Code: Select all
Dim b as Byte
Sub Main()
Select Case (b)
Case Asc("0")
Debug.Print "xx"
End Select
End Sub
Code: Select all
Sub Main()
Select Case (b)
0019 1d4001 PSHA_B 0x0140 (320)
001c 1a30 PSHI_B 0x30 (48)
001e a0 CMPEQ_B
001f 030300 BRA_T 0025
0022 010800 BRA 002d
Case Asc("0")
Debug.Print "xx"
0025 09027878 PSHI_S "xx"
0029 fe26 SCALL OUTSTR
002b fe27 SCALL OUTEOL
End Select
End Sub
002d 06 RET
Code: Select all
Sub Main()
Select Case (b)
0019 1d4001 PSHA_B 0x0140 (320)
001c 090130 PSHI_S "0"
001f 1b0100 PSHI_W 0x0001 (1)
0022 fe1b SCALL STRASC
0024 a0 CMPEQ_B
0025 030300 BRA_T 002b
0028 010800 BRA 0033
Case Asc("0")
Debug.Print "xx"
002b 09027878 PSHI_S "xx"
002f fe26 SCALL OUTSTR
0031 fe27 SCALL OUTEOL
End Select
End Sub
0033 06 RET
Code: Select all
Private Const Expr1 as Byte = Asc("0")