UDT construction as a proper way to Cast, not mentioned

Forum for discussion about the documentation project.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Cast a generic

Post by Tourist Trap »

fxm wrote: Can you post a code example of using that '@UDT' which is not an instance?
You are right!
I fell into this every 2 months... As suggested in the past, I probably would be happy with a syntax like [UDT] to play with the static version of the UDT.

However, I dont understand. Look well at the example below. I can not catch a non static stuff designed by THIS, but I can do this with the alias UDT in the case of the constructor, that hides THIS inside!
How then to access the destructor or other functions (instance , not the statics), since they all rely in THIS to be named ?

Code: Select all

 type UDT
    declare constructor()
    declare destructor()
    declare static sub S()
    declare sub T()
    as integer x
end type
constructor UDT()
    var r = @UDT
    var v = @UDT.S
    '
    var u = @THIS.constructor()   ''??
    var u = @THIS.destructor()   ''??
    var w = @THIS.S   ''?
end constructor
destructor UDT()
    '
end destructor
sub UDT.S()
    '
end sub
sub UDT.T()
    '
end sub

? @UDT
? @UDT.S

var u = @UDT
var v = @UDT.S
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: UDT construction as a proper way to Cast, not mentioned

Post by fxm »

Presently, FreeBASIC does not still support pointer to non-static member procedure.

Warning, 'var r = @UDT' inside the default constructor induces an infinite loop, because '@UDT' return the address of a temporary instance constructed by this same default constructor ('@UDT' does not return the address of the default constructor).
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: UDT construction as a proper way to Cast, not mentioned

Post by Tourist Trap »

fxm wrote:Presently, FreeBASIC does not still support pointer to non-static member procedure.

Warning, 'var r = @UDT' inside the default constructor induces an infinite loop.
Only on exception so, for the constructor. This at least proves that there is no fundamental impossibility.

Yes the example above is dummy, the true thing I was trying is to send the procedures addresses to another udt.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: UDT construction as a proper way to Cast, not mentioned

Post by fxm »

Tourist Trap wrote:Only on exception so, for the constructor. This at least proves that there is no fundamental impossibility.
No, see how I complemented my previous post.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: UDT construction as a proper way to Cast, not mentioned

Post by Tourist Trap »

fxm wrote:
Tourist Trap wrote:Only on exception so, for the constructor. This at least proves that there is no fundamental impossibility.
No, see how I complemented my previous post.
Ah thanks.

If I say now that the constructor designed by @UDT is not a sub and behaves like a function returning byref, am I closer to the truth? Probably it's nothing that we can emulate, I will however do some tests to check what is caught by var x = @func_byref.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: UDT construction as a proper way to Cast, not mentioned

Post by fxm »

I think that the predefined operator @ returns a pointer by value:
@ (Address of)
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: UDT construction as a proper way to Cast, not mentioned

Post by fxm »

Code: Select all

 type UDT
    declare constructor()
    as integer x
end type
constructor UDT()
    var r = @UDT      '' the non-shortened syntax is: @UDT()
    #print typeof(r)  '' UDT PTR
end constructor

Code: Select all

Function f () Byref As Integer
  Static As Integer I
  Return I
End Function

#print typeof(@f)    '' FUNCTION() BYREF AS INTEGER
#print typeof(@(f))  '' INTEGER PTR     the non-shortened syntax is: @(f())
Post Reply