pdwyer wrote:When I look at your code I think "is .Long a type defined somewhere with a \l as a member?"
Yes. All the Purebasic native types have defined a corresponding structure.; for .w there is the structure .WORD with one member field; namely \w. So the following could be used in place of PokeW() etc.
Take a look at the structure viewer in the Purebasic IDE\tools menu.
As for pointers themselves, they are not as 'far reaching' in PB as with some other languages and can essentially only be used as 'pointers to structures'. This means of course in order to have a pointer to a string, for example, you need to define a pointer to a structure of type STRING which has a member variable \s etc.
However, because of this 'simplification' things are a damn sight easier where pointers are concerned and they are just as powerful really. Okay, pointers to pointers require a little fiddling, but it is all very logical. In fact, you will undoubtedly have noticed by now that there is no BY REF command with procedure parameters. All parameters are passed by value. The only way to mimick 'BY REF' is actually to explicitly pass the address of a variable/structure and use a pointer to receive the address:
Code: Select all
Procedure ByRef(*ptr.LONG)
*ptr\l = 20
EndProcedure
;Define a variable of type long.
a.l=10
;Output the value of a. (=10)
Debug "a = " + Str(a)
;Call the above proc, passing the address of a as a parameter.
ByRef(@a)
;Output the value of a. (=20)
Debug "a = " + Str(a)
and I actually find this a very nice way of doing things. Of course you could achieve the above results with Peek and Poke etc. but it's not as nice - or as efficient.
One reason you'll see a lot of Peek's and Poke's is simply because they are often quicker to code when dealing with pointers to pointers and such like. They require more processing however so there is something to be gained by avoiding them where possible.
I may look like a mule, but I'm not a complete ass.