Page 1 of 1

More Flexible Structure Extends

Posted: Mon Apr 29, 2019 2:45 am
by deathmx
This would really help in cleaning up structures.

Code: Select all


Structure IsBeautiful
 AlwaysisBeautiful.i  
EndStructure

Structure IsGettingMoreBeautiful
  AlwaysisgettingmoreBeautiful.i
EndStructure



Structure Purebasic
  
  Extends IsBeautiful
  
  astimepasses.i
  
  Extends IsGettingMoreBeautiful
  
EndStructure


Creates:

Structure Purebasic
  AlwaysisBeautiful.i  
  astimepasses.i
  AlwaysisgettingmoreBeautiful.i
EndStructure

;yes i maybe kissing ass.. but, I do love this language lol.


Re: More Flexible Structure Extends

Posted: Mon Apr 29, 2019 9:17 am
by mk-soft
It would violate the rules of structural extension.

Re: More Flexible Structure Extends

Posted: Mon Apr 29, 2019 9:27 am
by deathmx
Please elaborate :) , it can still eaisly be made compatible with the previous behaviour.

Is there is something i missing?

Re: More Flexible Structure Extends

Posted: Mon Apr 29, 2019 12:27 pm
by #NULL
PureBasic only supports single inheritance, not multiple inheritance. So in the following example the procedure p() can access \a always at the same offset (at the beginning of the structure), even if an sB or sC object is passed to p().

Code: Select all

Structure sA
  a.i
EndStructure

Structure sB Extends sA
  b.i
EndStructure

Structure sC Extends sB
  c.i
EndStructure

Procedure p(*p.sA)
  Debug *p\a
EndProcedure

Define.sA a\a = 11
Define.sB b\a = 22
Define.sC c\a = 33

p(@a) ; 11
p(@b) ; 22
p(@c) ; 33

Debug OffsetOf(sA\a) ; 0
Debug OffsetOf(sB\a) ; 0
Debug OffsetOf(sC\a) ; 0
With multiple inheritance like this..

Code: Select all

Structure sX Extends sB, sA
  x.i
EndStructure
..either sB or sA will be at a different offset than 0, so for passing an sX to p() the offset of \a will be different than if an sA is passed.

Re: More Flexible Structure Extends

Posted: Mon Apr 29, 2019 1:07 pm
by deathmx
Sorry, looks like i wasn't clear. I was actually requesting Multiple Inheritance.


Somewhat like this... it would be nice to do this without macros. Especially since ide doesn't detect whats going on in the macros.

Code: Select all


Macro Extends_SA
  a.i
EndMacro

Macro Extends_SB
  
  b.i
  Extends_SA
EndMacro


Structure SA
  a.i
EndStructure

Structure SB
  
  b.i
  Extends_SA
EndStructure

Structure sC
  c.i
  Extends_SB
EndStructure

Procedure p(*p.sA)
  Debug *p\a
EndProcedure

Define.sA a\a = 11
Define.sB b\a = 22
Define.sC c\a = 33

p(@a) ; 11  11
p(@b) ; 22   0
p(@c) ; 33   0

Debug OffsetOf(sA\a) ; 0  0
Debug OffsetOf(sB\a) ; 0  8
Debug OffsetOf(sC\a) ; 0  16




Re: More Flexible Structure Extends

Posted: Tue Apr 30, 2019 4:13 am
by Demivec
Your request is similar to anonymous structures and anonymous unions.