View Single Post
Old 07 June 2016, 21:27   #2
Cylon
Registered User

 
Join Date: Oct 2014
Location: Europe
Posts: 466
I've expanded the example from a while ago:

Code:
NEWTYPE.foo
  a.w
  b.w
  c.w
End NEWTYPE

DEFTYPE.foo   tsrc    ;create a variable of the new type, means actually malloc()

tsrc\a=10,20,30

*tdst.foo = tsrc    ;grab the address of the memory where our nt variable is 

If *tdst               ;is this a valid address?
  NPrint Hex$(*tdst)

  NPrint *tdst\a
  NPrint *tdst\b
  NPrint *tdst\c
;
;*tdst=0    ;make sure we are not trying to free that later
EndIf


Statement zorg {ntaddr.l}

If ntaddr>0     ;better check all times
  *dummy.foo=ntaddr
  NPrint Hex$(*dummy)

  NPrint *dummy\a
  NPrint *dummy\b
  NPrint *dummy\c

  *dummy=0
EndIf

End Statement


zorg {tsrc.foo}

zorg {*tdst}


MouseWait
End
Please mind this way you are using the variable (type) itself, normally a new one would have been created (copied) inside the Function. This is not the case here, we are passing the address only.
Hope this helps.

*Edit: With a little bit more information about your goals i might have other ideas. The above example is (as it is now) useless, as it could be done by simply declaring the ntype as SHARED inside the Function.

Last edited by Cylon; 10 June 2016 at 02:14. Reason: added src comments
Cylon is offline  
 
Page generated in 0.06493 seconds with 11 queries