The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

    • RT @michaelbolton: 1) Your periodic reminder: a test is not something we *write*. We write text and programs. A test is an experiment you *… 1 hour ago
    • RT @BiancaPrins: Voor ons allemaal, een #draadje om tot het einde te lezen..... Juist nu (Volgt nog meer in de komende dagen) https://t.co… 1 hour ago
    • RT @McKayMSmith: 90) His entire life, Ben has chosen to place his faith in the law. “Law, not war” has been his motto for decades. “I hav… 1 hour ago
    • RT @McKayMSmith: 82) “It's possible to take the most fundamental, strongly held ideas and change them. What makes people change? Sometimes… 1 hour ago
    • RT @McKayMSmith: 65) “Now I will tell you something very profound, which I have learned after many years. War makes murderers out of otherw… 1 hour ago
  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,640 other followers

Smart Pointers code that compiles in FPC and Delphi

Posted by jpluimers on 2019/03/06

Delphi and FPC have different language boundaries, so it is always good to read a thread discussing how to get near-the-edge cases work in both.

This case is about Smart Pointers (here called auto pointers, maybe because auto_ptr is what they used to be called in C++): [WayBack] Hi all, I am trying to make a certain piece of code cross compile between Delphi and FPC. On FPC, it compiles fine but on Delphi I get a [dcc32 Error] P… – Ugochukwu Mmaduekwe – Google+

In the end if comes down to that Delphi does not allow forward-declaration of records (it does for interfaces and classes), but that you do not need a __PAutoPtr_T = ^__TAutoPtr_T, because you can use ^__TAutoPtr_T in parameters.

In Spring4D, they are called Shared/IShared/TShared, see my comment:

Note that since these are reference counted, you might want to call them shared_ptr. If you enforce the single-instance behaviour, observe that in C++ they are now called uniqe_ptr.

In Spring4D this rename has already taken place a while ago: https://bitbucket.org/sglienke/spring4d/commits/e252b81fd3788cf5b82588721f68d00c892deb87

–jeroen

2 Responses to “Smart Pointers code that compiles in FPC and Delphi”

  1. rvelthuis said

    ” Delphi does not allow forward-declaration of records (it does for interfaces and classes”.

    Of course not! Interfaces and classes are reference types (i.e. pointers), so there is no problem with them. But records are value types.

    You can forward reference POINTERS to records, as long as they are in the same type block. It is done hundreds of times in many of the Delphi sources.

    • rvelthuis said

      If you could forward record types, you could theoretically include a record in itself, which would cause some kind of infinite recursion in the compiler and which would be an impossible type.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: