Computer Science Canada [Quick-Tip] "Pointers" C-Style |
Author: | Clayton [ Thu Jun 14, 2007 10:12 pm ] | ||
Post subject: | [Quick-Tip] "Pointers" C-Style | ||
This is just a quick little thing I discovered today when trying to help a friend out. After coding in languages like C, being able to point to just about anything becomes quite handy, and when back in Turing, not being able to do so can be a bit bothersome. However, with a bit of searching, I have come up with a workaround.
The beauty of this is that it actually almost reads like English. We create a variable called foo to store our integer 4. Then we create our "pointer" that is given the address of that integer's location in memory via the function addr(). Note that address must be of the type addressint. Then we output foo to prove a point, then we say, "make the integer at the address 'address' become 42". Genius. I should also note this works for any type, just be sure to change any instance of int (except in addressint, that stays the same) to the type that you wish it to be. |
Author: | Clayton [ Thu Jun 14, 2007 10:34 pm ] | ||
Post subject: | Re: [Quick-Tip] "Pointers" C-Style | ||
Well then! It seems that you can actually use pointers like C-style pointers in Turing after all.
In Turing, for you to be able to point to any arbitrary piece of data, you must first declare your pointer as unchecked, then you must create a new instance of it, dereference it with the karot ('^') and give it a value. Then you can do whatever you like with it! |
Author: | tenniscrazy [ Fri Jun 15, 2007 10:53 am ] |
Post subject: | RE:[Quick-Tip] "Pointers" C-Style |
you can use practiacally all of C coding in turing, cause turing is writen in C, so i guess they just included that also: var a : int loop a += 2 end loop |