GPWiki.org
GPWiki.org
It is currently Mon May 20, 2013 7:24 am

All times are UTC




Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Sat Apr 21, 2012 11:32 am 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
Alberth wrote:
@IGTHORN: Sorry, but I didn't see a nice way to start a new topic, feel free to split the topic.

That was directed towards aestond, for future reference. Seeing as he's asking the questions :)

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
PostPosted: Sat Apr 21, 2012 12:18 pm 
Shake'n'Baker

Joined: Thu Dec 29, 2011 2:33 pm
Posts: 62
IGTHORN: I thought it might be good to have everything in one
thread, so I won't open too much new noob-threads.

But you point of view seems to be better,
for the next, topic-non-related questions, I will open
a new thread.
Thanks :)


Top
 Profile  
 
PostPosted: Sun Jul 15, 2012 11:43 am 
Shake'n'Baker
User avatar

Joined: Fri Feb 05, 2010 1:11 pm
Posts: 52
Location: MiddleEurope
How about avoiding pointers in your program at all costs?
As much as I read, either in the forum or in online tutorials, pointers are really a bite in the ass.
Though they may store an adress for you (and you can use even regular variables for common stuff), they will sooner or later become
traitors in your midst. (As I have read your issue, Alberth, about "pointers to pointers" :eek )

Isn't there a plan to follow to make the program we are building come to a successful end?
I mean by following security notions such as "avoiding pointers at all costs", etc.

_________________
Even this world is "programmed" by a Creator, the most skilled programmer of us all. What do you think of all that exists and all the environmental phenomena? He that maketh all had programmed it all and whenever needed, He can call one of the functions with input specified by Him. :)


Top
 Profile  
 
PostPosted: Sun Jul 15, 2012 4:05 pm 
Bytewise

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 276
Location: Here (where else?)
If you can do everything with integers and floats, that would work.

However, helloworld.cpp already uses a pointer to an array of characters (ie a "Hello world" string literal).
When writing more complicated programs, you tend to use pointers even more.

Therefore, I think avoiding pointers is not an option, you'd cripple the language severely and make your own life a lot more complicated.
In my opinion, a better strategy is to understand them, and use them wisely.

Pointers themselves are usually not the real problems. The real problems are the implicit assumptions that go with it which are never told in a tutorial (or maybe I read the wrong manuals :p ), namely lifetime of the data pointed to, and ownership of the data. If you mess these up, you'll have many 'interesting' hours reading code and using a debugger :p

Starting with the latter, each piece of data needs to have a single owner at all times. It is the object responsible for deleting (free-ing) the data at the end. Thus for each use of a pointer, you have to know whether this pointer carries ownership of the pointed-to data or not.
If it doesn't, you can let go of the pointer without doing anything. If it does, you need to either transfer ownership of the data first, or you need to delete the data.

The second problem is lifetime. The owner deletes the data at the end of its life time. Obviously, nobody should use that data at that point. Thus, for each pointer that you give away (which does not carry ownership along with it), you have to ask yourself when the pointer will stop being used, so you know when it is safe to delete the data.

That is basically all there is too it. Not messing up is however the challenge :)

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group