Why does typed address operator not apply when taking the address of a string element?

Viewed 330

This program

{$T+}

var
  PA: PAnsiChar;
  PW: PWideChar;
  s: string;

begin
  PA := @s[1];
  PW := @s[1];
end.

compiles. I would expect that with {$T+} that one of the assignments would have been rejected by the compiler. In modern Unicode Delphi I would expect the first assignment to be invalid.

The documentation for type-checked pointers says:

When @ is applied to a variable reference in the {$T+} state, the type of the result is ^T, where T is compatible only with pointers to the type of the variable.

Why does using typed addresses not seem to apply to the code above?

0 Answers
Related