Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.


9.2.4 Finding addresses (making pointers)

If a program knows the address of a variable it can directly read or alter the value stored in the variable. To obtain the address of a simple variable you use `{' and `}' around the variable name. The address of non-simple variables (e.g., objects and arrays) can be found much more easily (see the appropriate section), and in fact you will very rarely need to use {var}. However, if you understand how to explicitly make pointers with {var} and use the pointers to get to data, then you'll understand the way pointers are used for the non-simple types much more quickly.

Addresses can be stored in a variable, passed to a procedure or whatever (they're just 32-bit values). Try out the following program:

DEF x

PROC main()
  fred(2)
ENDPROC

PROC fred(y)
  DEF z
  WriteF('x is at address \d\n', {x})
  WriteF('y is at address \d\n', {y})
  WriteF('z is at address \d\n', {z})
  WriteF('fred is at address \d\n', {fred})
ENDPROC

Notice that you can also find the address of a procedure using `{' and `}'. This is the memory location of the code the procedure represents, although it is not something we need concern ourselves with any further in this Guide. Here's the output from one execution of this program (don't expect your output to be exactly the same, though):

x is at address 3758280
y is at address 3758264
z is at address 3758252
fred is at address 3732878

This is an interesting program to run several times under different circumstances. You should see that sometimes the numbers for the addresses change. Running the program when another is multi-tasking (and eating memory) should produce the best changes, whereas running it consecutively (in one CLI) should produce the smallest (if any) changes. This gives you a glimpse at the complex memory handling of the Amiga and the E compiler.


Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.