Page 1 of 1

Procedures return pointers with types

Posted: Thu Nov 01, 2007 1:20 am
by tinman
It would be nice to be able to return a pointer from a procedure and maintain the structure being pointed to. For example, this would be nice:

Code: Select all

Structure foo
    a.l
    b.l
EndStructure

*Procedure.foo return_foo_ptr(*return_me.foo)
    ; Or maybe just "Procedure.foo" and assume it's always a pointer that's returned
    ProcedureReturn *return_me
EndProcedure

Define.foo a_foo
Define.foo *a_ptr

return_foo_ptr(@a_foo)\a = 23
; same as:
;*a_ptr = return_foo_ptr(@a_foo)
;*a_ptr\a = 23
Thanks.

Posted: Thu Nov 01, 2007 3:06 am
by Hroudtwolf
Hi,

This works... ;-)
It's just one identifier more, you have to use.

Code: Select all

Structure foo
    a.l
    b.l
EndStructure

Procedure MyFunc ()
    Protected *return_me.foo = AllocateMemory (SizeOf (foo))
    *return_me\a = 123456
    *return_me\b = 7890
    ProcedureReturn *return_me
EndProcedure 

Define.foo *blub = MyFunc ()
Debug *blub\a
Debug *blub\b
Best regards

Wolf

Posted: Thu Nov 01, 2007 9:40 am
by tinman
Hroudtwolf wrote:This works... ;-)
It's just one identifier more, you have to use.
I know, I posted that as the comparison of what the feature would be the same as.