Recent

Author Topic: [SOLVED] Generic Linked List in Free Pascal  (Read 3190 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 19129
  • Glad to be alive.
Re: Generic Linked List in Free Pascal
« Reply #15 on: August 06, 2025, 08:29:46 am »
But it isn't an advanced record, so it is a bug.....
Unless it is now specified that a simple generic record has also become an advanced record since 3.2.2.
That is because this is a regression.
But indeed, same code compiles in 3.2.2, but need the modeswitch added in 3.3.1. for it to compile.

Bugs are bugs, regressions are regressions.
« Last Edit: August 06, 2025, 08:34:21 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

skepta

  • New member
  • *
  • Posts: 8
Re: Generic Linked List in Free Pascal
« Reply #16 on: August 07, 2025, 06:50:05 pm »
Hi, thank you for all for your answers. I would like to highlight 2 answers:

1. From PascalDragon + bytebites
The answer is great, but we need to add {$ModeSwitch advancedrecords}. For me this means I'm not good at Pascal yet. I actually got confused by the many dialect and many switches of Pascal. Other language seems more standardized.
My initial goal is to only use fpc dialect, but nowadays I think I'm also interested objfpc mode. The added benefit of using objfpc is FPC itself is implemented in it, which means a lot to me since I want to learn FPC source code.

2. From avk
The answer is great too. This makes me think again, why is ^TNode and Pointer (and ^specialize TNode<_T>) the same? Maybe I shouldn't overthink it and just use the original implementation (Pointer) instead.

I will close this thread soon.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6392
  • Compiler Developer
Re: Generic Linked List in Free Pascal
« Reply #17 on: August 07, 2025, 08:22:14 pm »
But why not just
Code: Pascal  [Select][+][-]
  1.   generic TNode<T> = record
  2.     Value: T;
  3.     Next: ^TNode;
  4.   end;
  5.  
?

That's possible as well, but specialize TNode<T> is the more precise solution, especially once mode ObjFPC supports type overloading as well like mode Delphi does.

With PascalDragon's code in objfpc mode I get an internal error.
intvsgeneric.pas(6,28) Fatal: Internal error 2019112401

Huh?! :o Seems like a regression, cause in 3.2.2 it works. Please report a bug so it isn't forgotten.

1. From PascalDragon + bytebites
The answer is great, but we need to add {$ModeSwitch advancedrecords}. For me this means I'm not good at Pascal yet. I actually got confused by the many dialect and many switches of Pascal. Other language seems more standardized.
My initial goal is to only use fpc dialect, but nowadays I think I'm also interested objfpc mode. The added benefit of using objfpc is FPC itself is implemented in it, which means a lot to me since I want to learn FPC source code.

$ModeSwitch AdvancedRecords shouldn't be required and in fact in 3.2.2 it isn't, so as said above that's a bug that needs to be fixed (by us).
And yes, there are many Pascal dialects, that's simply how it is, because the standardized Pascal dialects (ISO Pascal and ISO Extended Pascal never took really off 🤷‍♀️ ).

 

TinyPortal © 2005-2018