Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-11

Is there a way to create a generic pointer to a generic record

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Le Duc Hieu

Hi,

I'm trying to write a generic linked-list without the use of classes and objects.

I need to be able to create generic pointer like this:

Type
  generic PGList<T> = ^specialize TGList<T>;

Reply by email

Le Duc Hieu
to Le Duc Hieu

Here is the complete snippet that i wanted to create

Type
  generic PGList<T> = ^specialize TGList<T>;
  generic TGList<T> = record
    data: T;
    next: specialize PGList<T>
  end;
Le Duc Hieu wrote 12 lines
Hi, I'm trying to write a generic linked-list without the use of classes and objects. I need to be able to create generic pointer like this: Type generic PGList<T> = ^specialize TGList<T>;

Reply by email

Sven Barth
to Le Duc Hieu
"Le Duc Hieu" wrote 11 lines
Here is the complete snippet that i wanted to create Type generic PGList<T> = ^specialize TGList<T>; generic TGList<T> = record data: T; next: specialize PGList<T> end;

You'll need to use nested types (they require modeswitch advancedrecords), like this:

=== code begin ===

type
  generic TGList<T> = record
  public type
    TSelf = specialize TGList<T>;
    PGList = ^TSelf;
  public
    data: T;
    next: PGList;
  end;

=== code end ===

Note: the TSelf construct is currently needed due to a bug in the compiler.

Regards,
Sven

Reply by email

Le Duc Hieu
to Sven Barth

Is there any entry on Mantis for me to keep track of this bug status?

Thanks.

Sven Barth wrote 39 lines
Am 20.11.2016 08:31 schrieb "Le Duc Hieu" : > > Here is the complete snippet that i wanted to create > > > Type > generic PGList<T> = ^specialize TGList<T>; > > generic TGList<T> = record > data: T; > next: specialize PGList<T> > end; You'll need to use nested types (they require modeswitch advancedrecords), like this: === code begin === type generic TGList<T> = record public type TSelf = specialize TGList<T>; PGList = ^TSelf; public data: T; next: PGList; end; === code end === Note: the TSelf construct is currently needed due to a bug in the compiler. Regards, Sven _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Sven Barth
to Le Duc Hieu: Is there any entry on Mantis for me to keep track of this bug status? Thanks. On Sun, Nov…
Le Duc Hieu wrote
Is there any entry on Mantis for me to keep track of this bug status?

I've fixed that bug now (it did already work in mode Delphi by the way), so now you can use this:

=== code begin ===

type
  generic TGList<T> = record
  public type
    PGList = ^specialize TGList<T>;
  public
    data: T;
    next: PGList<T>;
  end;

{ or even }

  generic TGList<T> = record
    data: T;
    next: ^specialize TGList<T>;
  end;

=== code end ===

Please note that the specialization must always be *inside* the record and the top one needs modeswitch advancedrecords due to the type section.

Regards,
Sven

Reply by email