V: and VarPtr Functions

Purpose

Returns the address of a variable or an array element.

Syntax

% = V:x

% = VarPtr(x)

x:name of a variable of any type

Description

V: and VarPtr are synonymous and, in the case of strings, return the address of the string itself (not the descriptor address), in the case of arrays they return the address of an array element and in the case of simple variables the address of the variable.

Example

OpenW # 1

Local c%

Dim a(3) As Double

// prints the address of a(3)

Print VarPtr(a(3))

// prints the address of c%

Print VarPtr(c%)

Local b$ = "Test"

Print "Get the string using Char{addr} of b$: "; _

Char{V:b$}

Print "Address of b$: "; V:b$

Print "Descriptor of b$: "; * b$

Print "Length of b$: "; Int{V:b$ - 4}

Remarks

The descriptor of a string contains the length of the string, is 4 bytes long, and is located right in front of the actual data. The descriptor address is obtained using ArrPtr(a$) or *a$.

See Also

ArrPtr, *

{Created by Sjouke Hamstra; Last updated: 04/09/2022 by James Gaite; Other Contributors: Jean-Marie Melanson}