Pointer to variable

Just starting out? Need help? Post your questions and find answers here.
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Pointer to variable

Post by MrTAToad »

Having problems with the values modified in variables that are passed as pointers to functions :

Code: Select all

EnableExplicit

Declare.b callback(*one)

Define one

one=9876
Debug "Before : "+Str(one)
callback(@one)
Debug "After : "+Str(one)

  Procedure.b callback(*one)
    *one=1234
    Debug "Changed to : "+Str(*one)
  EndProcedure
For some reason one is always 9876, even though a pointer to one is passed to be modified.

The output is thus :

Before : 9876
Changed to : 1234
After : 9876
Sirius-2337
Posts: 35
Joined: Wed Mar 26, 2014 5:47 pm

Re: Pointer to variable

Post by Sirius-2337 »

According to Fred this is a limitation of SB (http://forums.spiderbasic.com/viewtopic ... rt=2#p1725)


You could write your code like this:

Code: Select all

EnableExplicit

Declare.b callback(*one.Integer)

Define one.Integer

one\i=9876
Debug "Before : "+Str(one\i)
callback(@one)
Debug "After : "+Str(one\i)

Procedure.b callback(*one.Integer)
  *one\i=1234
  Debug "Changed to : "+Str(*one\i)
EndProcedure
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Re: Pointer to variable

Post by MrTAToad »

Ah, right - thanks for that.
Post Reply