Name

$TypedAddress Compiler Directive

Syntax

{$T-}               // default
{$TypedAddress Off} // default
{$T+}
{$TypedAddress On}

Scope

Local

Description

When $TypedAddress is enabled, the @ operator returns a typed address of a variable or subroutine. The default is that the @ operator returns a generic Pointer type. Even when $TypedAddress is enabled, assignments of a typed pointer to the Pointer type are still allowed as are assignments from Pointer to a specific pointer type.

Tips and Tricks

  • Enable $TypedAddress because it encourages good programming practices and careful use of pointers. Unsafe pointer assignments can be caught at compiler time.

  • The Addr function always returns an untyped Pointer. If you enable $TypedAddress, use Addr when you need an untyped pointer and use @ when you want a type-safe address.

Example

var
  P: PInteger;
  Q: ^Double;
  I: Integer;
begin
{$TypedAddress On}
  P := @I;
  Q := @I; // not allowed because types don't match
{$TypedAddress Off}
  Q := @I; // allowed, even though types don't match

See Also

@ Operator, Addr Function, Pointer Type
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset