NAME

varptr - memory offset of a variable

SYNOPSIS

offset = varptr(Var)
offset = varptr(#FileNum)

DESCRIPTION

Var is the name of a numeric or string variable or array element.  FileNum is the number of an open file.  Seg is a predefined variable in Basmark QuickBASIC which always contains the high-order bits of the address which defines the current segment.  Its value is used to define the high-order bits for a peek or poke operation.  Its value is automatically set by a varptr operation.  Seg can be explicitly set using def seg. 

EXAMPLE

	 1 option base 1
	 5 dim src%(50), dst%(50)
	10 srcoff% = varptr(src%)
	15 srcseg% = seg
	20 dstoff% = varptr(dst%)
	25 dstseg% = seg
	30 for i% = 1 to 100
	35	def seg = srcseg%
	40	temp% = peek(srcoff%)
	45	def seg = dstseg%
	50	poke dstoff%, temp%
	55	srcoff% = srcoff% + 1
	60	if srcoff% = 0% then srcseg% = srcseg% + 1%
	65	dstoff% = dstoff% +1
	70	if dstoff% = 0% then dstseg% = dstseg% + 1%
	80 next i%
The example illustrates the use of varptr in an unusual means of copying the array src% to the array dst%.  Varptr is used in lines 10 and 20 to assign the lower 16-bits of the 32-bit addresses (the offsets) to the variables srcoff% and dstoff%.  The value of seg (the high-order 16-bits of the addresses) for each of the arrays is saved (in lines 15 and 20) in the variables srcseg% and dstseg% for later use in lines 35 and 45.  The for...next loop (lines 30-80) increment the offsets (lines 55 and 65) and check for segment incrementing (lines 60 and 70).  The poke (line 50) effects the swap.  Of course, there are better ways to copy arrays.  This method is shown only to illustrate the varptr function. 

SEE ALSO

peek, poke, def seg, seg

DIAGNOSTICS

If FileNum is less than 1 or greater than the maximum number of open files, a "Bad file number" error occurs. 

USAGE NOTES

When implemented in a 32-bit environment, Basmark QuickBASIC requires that the high-order 16 bits be predefined by means of the def seg statement, leaving the low-order 16 bits as an offset returned by varptr, and used as an argument by peek and poke.  The high order 16 bits of the address are stored in the seg variable. 

from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber