http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Beginner question



The one thing to be aware of with pointers is that since you are directly
addressing memory, you can actually change some portion of memory which is
not what you thought  it was.  That sounds confusing, but happens when you
use a pointer which hasn't been initialized before you use it (i.e. make
sure you set where the pointer points to (ptrTemp = new XZY), before setting
or reading the value the pointer points to (*ptrTemp = 43 or abc =
*ptrTemp).  The other common problem with pointers is when you increment
them beyond the end of their allocated memory space, or decrement them be
before  the beginning of their allocated memory space (i.e.
char *ptrTemp = New int[2];

*ptrTemp++ = 12; // This is OK, we just set the first element to 12, and
have ptrTemp pointing to the second element
*ptrTemp++ = 34; // This is OK to set the value of the second to 34, but now
ptrTemp points to a third elelment which we didn't allocate
*ptrTemp = 56; // This is BAD because we just set the value of a third
element, but only allocated two elements, so we just wrote on top of some
other data...

Both unitialized pointers and pointing off the end of allocated memory can
be extremely hard bugs to track down.  So, just be careful, and try to make
sure that you don't let these bugs into your code.  Pointers are like cars,
when used properly, they are pretty much indispensible, but when used wrong,
they can cause big problems.

Good Luck and Have Fun!!!

Kevin Wolfskill
JADE Solutions
Office US   (303) 448-1019 ext. 23
Fax US      (303) 449-1548
Kevin.Wolfskill@jadesolutions.com
______________________________________
WARNING - THIS E-MAIL TRANSMISSION IS CONFIDENTIAL.
This e-mail transmission (including any accompanying attachments)
contains confidential information which is intended for the named addressee
only. If you are not the intended recipient, you are hereby notified that
any use, dissemination, distribution or reproduction of this e-mail is
prohibited. If you have received this e-mail in error please contact
me immediately. Thank you.
_______________________________________





-----Original Message-----
From: Frag_ Daddy [mailto:frag_daddy_@hotmail.com]
Sent: Friday, June 09, 2000 11:54 PM
To: gameprogrammer@gameprogrammer.com
Subject: Re: Beginner question




     You seem to have a basic understanding of what they are.  Yeah, they 
just point to a certan spot in the memory, but they have a lot of 
advantages.  For one, they can point to an array or something, so they don't

have to be just one object (kind of).  Also, they can just have a block of 
memory allocated (via malloc(...) or new).  This greatly improves the 
flexibility of C++.  This doesn't explain it too well, but I hope it helps a

little.



>From: wegifford <wegifford@GRUMPY.FORTLEWIS.EDU>
>Reply-To: gameprogrammer@gameprogrammer.com
>To: gameprogrammer@gameprogrammer.com
>Subject: Beginner question
>Date: Thu, 08 Jun 2000 20:28:51 -0600
>
>Hey there,
>    I am a beginner and I am covering pointers and have a few questions.  
>The
>book I am using is not giving me the best explanation.  The code makes tons

>of
>sense but I want to know a little more about what a pointer is.
>    As I understand it a pointer variable is pointing to a variable 
>location in
>memory.  So when passed in a function it is not exactly being passed but 
>where
>the variable is located is being pass. What is a pointer exactly used for?

>Is
>the previous explantion the answer.  If so when is the best time to declare
>and use pointers? What is a benefit of a pointer? Is it just speed?  Any 
>help
>you all could give would shed light on this concept.
>
>                                                         William
>
>
>=================================================================
>The GameProgrammer.Com mailing list is for the open discussion
>of any topic related to the art, science, and business of
>programming games. This list is especially tolerant of beginners.
>We were all beginners once
>
>To SUBSCRIBE or UNSUBSCRIBE please visit:
>http://gameprogrammer.com/mailinglist.html

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html