Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Quick-Tip] "Pointers" C-Style
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Clayton




PostPosted: 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.

Turing:

var foo : int := 4
var address : addressint := addr (foo)

put foo

int@(address) := 42

put foo


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.
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: 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.

Turing:

var foo : unchecked pointer to int := nil
var bar : int := 5

new foo

^foo := bar

put ^foo

var baz : unchecked pointer to boolean := nil
var qux : boolean := true

new baz

^baz := qux

put ^baz


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!
tenniscrazy




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: