On 24/03/2023 15:04, Benito van der Zander via fpc-pascal wrote:
why is a pointer to a char not a pchar (for type helpers)?

My guess: For the same reason that "p2" fails in the below. Distinct type.
May be assignment compatible, but a type of it's own.

Imagine you had a different helper, with a different "toString" on pchar2, then which one should @char get?

program Project1;
{$Mode objfpc}{$H+} {$ModeSwitch typehelpers}
type
  pchar = ^char;
  pchar2 = ^char;

type TPcharHelper = type helper for pchar
  function toString(length: integer): string;
end;

function TPcharHelper.toString(length: integer): string;
begin
end;

var
  p: pchar;
  p2: pchar2;
begin
  p.toString(1);
  p2.toString(1);  // error
end.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to