52 of 158
46 an error by the compiler. Arrays may only be passed by reference and then only if they are RAM-based, single-dimension and have a lower bound of 1. Allowed Parameter Passing Methods Actual Parameter Type Pass By Value Pass By Reference Constant or expression, any type Yes No RAM-based variable or array element Yes¹ Yes² RAM-based single-dimension array, 1-based No Yes RAM-based single-dimension array, not 1-based No No RAM-based multi-dimensional array No No Persistent variable or array element Yes No Persistent Memory array No No Program Memory array element Yes No Program Memory array No No Notes: ¹ String types and structures are read-only within the called routine when passed by value. ² The sub-byte types, Bit and Nibble, cannot be passed by reference. Also, in BasicX mode, UnsignedInteger and UnsignedLong types are read-only within the called routine when passed by reference. The table below gives the number of bytes of stack space required to pass different variable types using the two passing methods. Stack Usage by Parameter Type and Passing Method Actual Parameter Type Pass By Value Pass By Reference Boolean, Byte 1 2 Bit, Nibble 1 2² Integer, UnsignedInteger, Enum 2 2 Long, UnsignedLong, Single 4 2 String¹, structure 2 2 Array, any type n/a 2 Notes: ¹ Persistent strings, Program Memory strings and strings returned by functions all require 4 bytes of temporary data space (local to the caller) plus the 2-byte reference when passed to a routine other than a System Library routine. ² Sub-byte types like Bit and Nibble may only be passed by reference if they are byte aligned. See Section 3.24.1 for details. 2.15 Program and Data Item Properties Most data items, whether located in RAM, Persistent Memory or Program Memory have an associated property called DataAddress which evaluates to the address of the data item. The DataAddress property is applied to a data item by appending it to the data item’s name with a period separating them as illustrated by the example below. Dim b as Byte Dim addr as UnsignedInteger Sub Main() addr = b.DataAddress End Sub