[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.2.10.8 Pointer Types

 
pointer type identifier = ^type identifier;

A pointer of the type pointer type identifier holds the address at which data of the type type identifier is situated. Unlike other identifier declarations, where all identifiers in definition part have to be declared before, in a pointer type declaration type identifier may be declared after pointer type identifier. The data pointed to is accessed by `pointer type variable^'. To mark an unassigned pointer, the `nil' constant (which stands for "not in list") has to be assigned to it, which is compatible with all pointer types.

 
type
  ItselfFoo = ^ItselfFoo;  { possible but senseless }

PInt = ^Integer; { Pointer to an Integer }

PNode = ^TNode; { Linked list } TNode = record Key : Integer; NextNode: PNode; end;

var Foo, Bar: PInt;

begin Foo := Bar; { Modify address which foo is holding } Foo^ := 5; { Access data foo is pointing to } end.

GPC also suports pointers to procedures or function and calls through them. This is a non-standard feature.

 
program ProcPtrDemo (Output);

type ProcPtr = ^procedure (Integer);

var PVar: ProcPtr;

procedure WriteInt (i: Integer); begin WriteLn ('Integer: ', i : 1) end;

begin { Let PVar point to function WriteInt } PVar := @WriteInt;

{ Call the function by dereferencing the function pointer } PVar^ (12345) end.

See also: section 8.2.9 Pointer (Intrinsic).



This document was generated by Frank Heckenbach on May, 10 2002 using texi2html