Page 1 of 1

Pointers and things

Posted: Wed Mar 28, 2007 5:11 am
by gebe
Code updated for 5.20+

I hope this is the right place to post
and that <code>works(did I use it correcty?)
this is posted hoping it will help other to avoid my 'suffering' while trying to make sense out of the pointers.

Code: Select all

;***************************************************
;* *
;* Attemp to see if PURE BASIC works like C ? *
;* for Pointers and Referencing ,Dereferencing *
;* *
;* IIIMMMMPPPPOOOORRRRTTTTAAAANNNNTTTT *
;* *
;* Check the slight differences in dereferencing *
;* *
;***************************************************


OpenConsole();use console to display results
;Procs set in front of the program

Procedure setParam(*x.long,v.l)
  ;;;;Dereferencing *POINTER\L,B,S..
  *x\l=v;;;;;;;NEEDS '\L' to say pointer to LONG
  ;"\L" is like PokeL(.,.) in PokeL(*x,V)
  ;similar To C in a pinch.....
  ;The above line (7) should read:
  ;"the variable (unamed here) referenced to by a pointer to a LONG
  ;with no name in the procedure,but a reference to a PLACE in memory
  Debug *x\l
EndProcedure

;-------------------------------
Procedure getParam(*x.long)
  *x\l=987654321
EndProcedure
;===============================
;Program

xyz.l=1234567890;declare and set (similar to C
PrintN("The variable XYZ (Long) has the Value of : "+Str(xyz))
;show in console
Debug xyz;shown in debug window
PrintN("The variable is being modified by a call byRef to a ")
PrintN("function modifying the variable in its location @XYZ passed to (*X\L) ")
PrintN("pointer to a long called XYZ the new value passed by val as 456 ")
setparam(@xyz,456)
Debug xyz
PrintN("The variable XYZ (Long) NOW has the Value of : "+Str(xyz))
PrintN("")
received.l=0
PrintN("RX = "+Str(received))
Debug received
getParam(@received)
PrintN("after calling GetParam RX = "+Str(received))
Debug received
PrintN("")
PrintN("Let's now put it in XYZ which has now "+Str(xyz))
Debug xyz
setParam(@xyz,received)

PrintN("EXECUTING setParam(@xyz,received)")
PrintN("After setParam to received.")
PrintN("XYZ has now "+Str(xyz))
Debug xyz


saString.s="eeeeeeeeeeeeeeeeeeeeeeee"
Debug sastring
;*saString.string=@sastring
saStringvarptr= @sastring
*saStringptr.string= @saStringvarptr
*sastringptr\s="qwerty"
Debug sastring
;console loop to allow readind the results
Repeat
  Delay(1)
Until Inkey()<>""
That'all .

Please , your comments are welcome. ^
There must be some mistake up there |

gebe :)

Posted: Wed Mar 28, 2007 7:44 am
by Kaeru Gaman
code-tags look like this:
[code][/code]
you can use the button on the "post a reply"-site.
and you can edit your above post if you want to add code-tags.