[fpc-pascal] pointer to char vs pchar

Martin Frb lazarus at mfriebe.de
Fri Mar 24 15:29:43 CET 2023


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.



More information about the fpc-pascal mailing list