Vote UpVote

A hidden feature of $POINTERMATH directive in Delphi 2009

The Programming Works – The $POINTERMATH directive (introduced in Delphi 2009) allows to treat a typed pointer as a scaled ordinal or as an array. Here is a code sample that wouldn’t compile without $POINTERMATH turned ON {$POINTERMATH ON} procedure TForm1.Button1Click(Sender: TObject); var P, P1: PInteger; N: Integer; begin P:= @Self; N:= 2; P1:= P + N; // treats P as a scaled ordinal N:= P[N]; // treats P as an array ShowMessage(Format('%p -- %p -- %d', [P, P1, N])); end; But the following code is also OK, though $POINTERMATH is turned OFF: {$POINTERMATH OFF} procedure ...
Favorite? Off-Topic? Serg @ 2010-06-09 11:39


Visits: 30
Votes: 0
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News


Please login or register to use this functionality.
(click on this box to dismiss)