Re: [fpc-pascal] Make a distinct pointer type
I just noticed this still doesn't provide good type safety as MyPtr can be assigned an untyped pointer. Are pointers simply not an option here? Maybe we need classes for opaque pointer types instead? type _MyPtr = record end; MyPtr = ^_MyPtr; var p: Pointer; x: MyPtr; begin x := p; // Should be an error! end; Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Make a distinct pointer type
Hairy Pixels via fpc-pascal schrieb am Do., 1. Juni 2023, 03:16: > > > > On May 31, 2023, at 9:20 PM, Michael Van Canneyt via fpc-pascal < > fpc-pascal@lists.freepascal.org> wrote: > > > > Type aliases are always assignment compatible. > > btw, what does the "type" prefix do then? I thought that made them > non-aliases or distinct types. > It only makes a difference for the RTTI as well as overloading. Regards, Sven > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Make a distinct pointer type
> On May 31, 2023, at 9:20 PM, Michael Van Canneyt via fpc-pascal > wrote: > > Type aliases are always assignment compatible. btw, what does the "type" prefix do then? I thought that made them non-aliases or distinct types. Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Make a distinct pointer type
I'm trying to make an "opaque pointer" type for a c library so the types are just pointers but they should be incompatible. I guess I'll have to make all the records. > On May 31, 2023, at 9:20 PM, Michael Van Canneyt via fpc-pascal > wrote: > > 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; > Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Make a distinct pointer type
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. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Make a distinct pointer type
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; Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal