Computer Science Canada Using pointer to access a varible |
Author: | Catalyst [ Wed May 14, 2003 4:11 pm ] |
Post subject: | Using pointer to access a varible |
I believe in C++ its called dereferencing (not sure tho) I know how to do this stuff in c++ but dont know and cant find the turing syntax (does it exist?) I need to take a pointer to a variable then use it to change the value of the variable Also does anyone know how to take a variable then create a pointer to the variable? Any help would be appreciated.... |
Author: | Asok [ Wed May 14, 2003 4:20 pm ] |
Post subject: | |
I've used it in c++ many times but I don't really see the use for turing, since it's linear there is always a workaround instead of making a pointer. |
Author: | Catalyst [ Wed May 14, 2003 4:23 pm ] |
Post subject: | |
ive got class for handling events (its for an rts) in it ive got an array of pointers to real vars the class need to be able to access these variables on its own to execucte the action in the event (since the event will be dormant in a queue at times) Im sure i could get around this somehow but this is the way that would make it simplest for me |
Author: | Dan [ Wed May 14, 2003 5:15 pm ] |
Post subject: | |
you could probley just make them golabe. i tried to figer it out but so far it looks like this could not be done in turing |
Author: | Homer_simpson [ Wed May 14, 2003 5:28 pm ] | ||
Post subject: | |||
i think this only works for integers....
|
Author: | Catalyst [ Wed May 14, 2003 6:56 pm ] |
Post subject: | |
i cant make the vars global since the ones it uses are in a class the addr() thing ive looked at, it might work if i can work in some type cheating |
Author: | Catalyst [ Thu May 15, 2003 5:02 pm ] |
Post subject: | |
addr doesnt work it crashes turing when it is used with its operator (@) i think the might be a way to do it with bind |
Author: | Homer_simpson [ Thu May 15, 2003 5:07 pm ] | ||
Post subject: | |||
how bout
|
Author: | Homer_simpson [ Thu May 15, 2003 5:10 pm ] | ||||
Post subject: | |||||
aaaaaaahhhh.... i think this is what u need.... Note the pointer in the code
and here are some examples....
|
Author: | Catalyst [ Thu May 15, 2003 5:15 pm ] | ||||
Post subject: | |||||
pointers can only locate classes and collections in turing, and dont do all the things i need them to do I did find a solution, addr() does work The reason it crashed me was b/c i used it flexible arrays (which apprently screws up the mem addresses) Addr() can be used just like c++ (c) pointers get the address of is like so:
then u can dereference it with the @ operator
|
Author: | void [ Thu May 15, 2003 5:21 pm ] |
Post subject: | |
whoa!!!....i never knew you could dereference in turing....i always thought it was a basic level program lang....hmm....very interesting....now...if turing wasnt so goddamn slow at compiling and running...and didnt lag so much..then you could actually make something cool in there |
Author: | Homer_simpson [ Thu May 15, 2003 5:49 pm ] |
Post subject: | |
the code doesn't crash on my comp and it works as it's supposed to... |
Author: | Catalyst [ Thu May 15, 2003 6:32 pm ] |
Post subject: | |
it crashed on mine earlier because i was using flexible arrays that was code showing how to use it after i realized why i was crashing |
Author: | nate [ Thu May 15, 2003 6:42 pm ] |
Post subject: | homer has time |
Homer you have a lot of time on your hands to write all that code, do they not give you homework? Lol w.e At least your trying -Nate |
Author: | Catalyst [ Thu May 15, 2003 7:17 pm ] |
Post subject: | |
ref manual |
Author: | Martin [ Thu May 15, 2003 7:47 pm ] |
Post subject: | |
Why do you need to make a pointer to a variable? If worse comes to worse, you can just use records. type Int : record x : int end record |
Author: | Catalyst [ Thu May 15, 2003 7:48 pm ] |
Post subject: | |
i had thought of that but this is much less work in the end |
Author: | Homer_simpson [ Thu May 15, 2003 9:24 pm ] |
Post subject: | |
I remember when i used to do c and pascal it would make some programs much shorter but it always confused me...(i was like 10-12...) |