Please, help me...

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by talun.

To PureBasic programmers,
I'm new to PureBasic and I've a lot of problem to get accustomed with the "new" PureBasic rules.
By default, Win\DOS BASIC compilers (QuickBasic; PowerBasic and so on)pass parameters to a procedure by reference, while PureBasic seems to pass the parameters by value.
How I can make in order to pass the addresses of the parameters to the procedures in such way to modify them?
I have found a complicated way in order to make it but does not seem very corrected..

Procedure test(*a.l,*b.l)
PokeL(*a,2)
PokeS(*b,"b")
EndProcedure

x.l = 1
y.s = "a"

Debug Str(x)+","+y
test(@x,@y)
Debug Str(x)+","+y

Thanks to all
Sergio
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

Hello,

I suppose the following example will answer your question :

Procedure SwapL(a, b)
sa = PeekL(b)
sb = PeekL(a)
PokeL(a, sa)
PokeL(b, sb)
EndProcedure

ia.l = 12
ib.l = 13

Debug "ia=" + Str(ia) + " ib=" + Str(ib)
SwapL(@ia, @ib)
Debug "ia=" + Str(ia) + " ib=" + Str(ib)

ia.l = 1234
ib.l = 2345

Debug "ia=" + Str(ia) + " ib=" + Str(ib)
SwapL(@ia, @ib)
Debug "ia=" + Str(ia) + " ib=" + Str(ib)

Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Originally posted by fweil
I suppose the following example will answer your question :
Did you read his mind? Your code is almost the same as the first post ;p

talun:
The simple types in PB (.b, .w, .l, .f and .s) are more awkward to use pointers with because there is not a clean way to get access to the data (unlike structured variables) - using the "*variable" syntax will only give you access to the address of the variable.

Using Poke and Peek is one way to do it, and is OK to do.


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.40)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by talun.

Tinmann, many thanks for your answer. I will change my mental habits and I will use structures if I need to change procedure arguments.
bye
Sergio
Post Reply