[fpc-pascal] Make a distinct pointer type

Michael Van Canneyt michael at freepascal.org
Wed May 31 16:20:26 CEST 2023



On Wed, 31 May 2023, Hairy Pixels via fpc-pascal wrote:

> What's the best way to make a pointer type which is distinct so that the following snippet would give an error. I thought "type pointer" would do it but it doesn't seem to work.
>
> type
>  PA = type pointer;
>  PB = type pointer;
>
> var
>  a: PA;
>  b: PB;
> begin
>  a := b; // should give an error!
> end;

Type aliases are always assignment compatible.

As far as I know, there is no way to do what you want with just 'pointer'.

This will give an error:

Type
   RA = record end;
   RB = record end;
   PA = ^RA;
   PB = ^RB;

var
   a: PA;
   b: PB;
begin
   a := b;
end.

Michael.


More information about the fpc-pascal mailing list