Pointers and Address Variables

Rather than passing data directly, you may want to pass the address of a piece of data. Passing the address amounts to passing the data by reference. In some cases, such as in BASIC arrays, there is no other way to pass a data item as a parameter.

C and C++ programs always pass array variables by address. All other types are passed by value unless you use the address-of (&) operator to obtain the address.

The Pascal ADR and ADS types are equivalent to near and far pointers, respectively, in C and C++. You can pass ADR and ADS variables as ADRMEM or ADSMEM. BASIC and FORTRAN do not have formal address types. However, they do provide ways for storing and passing addresses.

BASIC programs can access a variable's segment address with the VARSEG function and its offset address with the VARPTR function. The values returned by these intrinsic functions should then be passed or stored as ordinary integer variables. If you pass them to another language, pass by value. Otherwise you will be attempting to pass the address of the address, rather than the address itself.

To pass a near address, pass only the offset; if you need to pass a far address, you may have to pass the segment and the offset separately. Pass the segment address first, unless CDECL is in effect.

FORTRAN programs can determine near and far addresses with the LOC and LOCFAR functions. Store the result of the LOC function as INTEGER*2 and the result of the LOCFAR function as INTEGER*4.

As with BASIC, if you pass the result of LOC or LOCFAR to another language, be sure to pass by value.