
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses




Task

Demonstrate how to get the address of a variable and how to set the address of a variable.




 
== Get ==
 
There are at least three ways to get the address of a variable in IWBASIC. The first is to use the address of operator:
 
DEF X:INT
PRINT &X
'This will print in the console window (after OPENCONSOLE is issued.) 
'To Print in an open window the appropriate Window variable is specified, e.g., PRINT Win,&X.
 
The second is to use a pointer:
 
DEF X:INT
DEF pPointer:POINTER
pPointer=X
 
The third is to use the Windows API function Lstrcpy. That is done in the same way as the Creative Basic example;
however, the function would be declared as follows: DECLARE IMPORT,Lstrcpy(P1:POINTER,P2:POINTER),INT.
 
== Set ==
 
It appears to the author that the closest one can come to being able to assign an address to a variable is to set
which bytes will be used to store a variable in a block of reserved memory:
 
DEF pMem as POINTER
pMem = NEW(CHAR,1000) : 'Get 1000 bytes to play with
#<STRING>pMem = "Copy a string into memory"
pMem += 100
#<UINT>pMem = 34234: 'Use bytes 100-103 to store a UINT
DELETE pMem
 