81 of 158
75 During the preprocessing, the symbols above will be replaced by their respective character values. Of course, there will need to be some code that refers to compData, otherwise the compiler will optimize it out. One caveat is that, as mentioned earlier, the substitution is done without regard to context. This will be a problem if you attempt to define a variable thusly: Dim a__LINE__b as Integer If this happens to occur on line 23 of the file the compiler will see this as Dim a23b as Integer However, on a different line a reference to a__LINE__b will yield a different variable name, probably causing the compiler to complain about use of an undefined variable. Since the preprocessor symbols are case sensitive but ZBasic identifiers are not, the simple workaround is to spell the variable name differently, e.g. Dim a__line__b as Integer 3.18 Array Data Order RAM-based arrays are stored sequentially in memory with the first index varying the fastest and the last index varying the slowest. Consider a two-dimensional array defined as: Dim ba(1 To 3, 1 To 2) as Byte The bytes of this array are assigned addresses in memory sequentially as: ba(1,1) ba(2,1) ba(3,1) ba(1,2) ba(2,2) ba(3,2) Whether this constitutes row-major order or column-major depends on whether you consider the first index of a two-dimensional array to be the column and the second index the row or vice versa. To a large extent, this is a non-issue as long as you remember that the first index varies the fastest. When thinking about Program Memory data tables, on the other hand, the perception does matter because the initializer data is arranged in rows and columns and you need to know how to get the array element that you want. To do so, always specify the column index first and the row index second. This order was adopted to maintain compatibility with the BasicX compiler. 3.19 Recursion in Subroutines and Functions A subroutine or function may be invoked recursively. This means that among the statements in the routine there is one or more that invokes the same subroutine or function again, either directly or indirectly. Clearly, the recursive invocation must be conditional so that at some point the recursion ceases. In Section 2.3.2, Defining Functions, an example function was given for computing factorial. Here is the same function written using recursion. Function Factorial(ByVal val as Integer) As Integer If (val > 1) Then Factorial = Factorial(val - 1) * val Else Factorial = 1 End If End Function