Procedures return pointers with types

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Procedures return pointers with types

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post 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
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Post Reply