[haiku-development] Re: Issue adding deskbar replicant from a server

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 20 Jan 2017 22:40:23 +0100

On 01/20/2017 03:53 PM, Dario Casalinuovo wrote:

On Fri, Jan 20, 2017 at 1:49 PM, Rene Gollent <anevilyak@xxxxxxxxx
<mailto:anevilyak@xxxxxxxxx>> wrote:

    On Fri, Jan 20, 2017 at 4:01 AM, Axel Dörfler
    <axeld@xxxxxxxxxxxxxxxx <mailto:axeld@xxxxxxxxxxxxxxxx>> wrote:
    > Nope, the return type is not part of the function signature -- it's the 
same
    > method, just more convenient to use.

    I forgot that last night for some reason, thanks for the correction.


Even if the return type doesn't affect the binary so the function is
found correctly, the bebook states BArchivable::Instantiate should
always return a BArchivable* object.

I'm not sure why is that though. Perhaps it was just a metrowerks
compiler bug.

With the ABIs we're using, a derived class return type is not a problem as long as you don't use multiple inheritance or, if you do, BArchivable is strictly in the first branch of ancestor classes. In that case the value of your class' pointer and the pointer to the BArchivable base object have the same value, so it doesn't matter, if instantiate_object() uses one for the other.

But you don't want to this in a case like:

  struct Foo {...};

  struct Bar : Foo, BArchivable {...};

Bar* and BArchivable* have different values and things will go horribly wrong, if Instantiate() returns a Bar*.

So the BeBook's advice to always declare the Instantiate() return type as BArchivable* is certainly not unreasonable.

CU, Ingo


Other related posts: