![]() ZBasic System Library
293
ZBasic Microcontrollers
Type
Function returning an integral value
Invocation
SizeOf(var)
Parameter
Method
Type
Description
var
ByRef
any type
The variable whose size, in bytes, is desired.
Discussion
This function returns the number of bytes constituting the supplied variable.
The primary purpose of this function is to allow writing code that is more easily maintained. For example,
instead of hard coding the size value to pass to the OpenQueue() subroutine, you can use
SizeOf(queue) instead. When you change the size of the queue there will be no need to update the
OpenQueue() calls.
When used with arrays, you may give the array name without any index parameters and SizeOf() will
return the total number of bytes occupied by the array. Alternately, you may specify constant expressions
for all of the array dimensions and SizeOf() will return the number of bytes occupied by a single
element of the array. This function is not particularly useful with sub-byte types (Bit and Nibble).
The SizeOf() function also allows the argument to name one of the fundamental data types (except
String). In this case it returns the number of bytes comprising the type. For example,
Sizeof(Integer) returns the value 2.
Example
Dim cnt as Integer
Dim val as Single
Dim ia(1 to 20) as Integer
cnt = SizeOf(val)
' result is 4
cnt = SizeOf(ia)
' result is 40
Compatibility
This function is not available in BasicX compatibility mode.
See Also
|