Path: chuka.playstation.co.uk!news From: Giulio Newsgroups: scee.yaroze.programming.codewarrior Subject: Re: Pointer usage (Was Re: Now I'm getting REALLY mad!) Date: Sun, 21 Dec 1997 11:18:55 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 61 Message-ID: <349CED0F.A1B363A0@tin.it> References: <34902D9A.A58C5281@tin.it> <01bd094f$aa411420$6c0b0a0a@newcastle.twowaytv.co.uk> <3496FC87.B1AD07DF@tin.it> <01bd0a92$e4e72b20$LocalHost@Angela1.intelligent-group.com> <349A9CA1.7E336240@tin.it> NNTP-Posting-Host: Genova9-89.tin.it Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 [en] (Win95; I) To: Joel Sumner Joel Sumner wrote: > > Hi Guilio, > I'm glad you posted your source for this. I think I know what's going > on. This may be helpful for others having this problem. > > In article <349A9CA1.7E336240@tin.it>, Giulio wrote: > > >typedef struct SpriteType > >{ > > GsSPRITE *SprBody ; // Body of the sprite using library > > int SprOld_X,SprOld_Y ; // Old sprite's position > > u_char AnimClock ; // Animation clock > > u_char AnimSpeed ; // Animation speed > > u_char MotionClock ; // Motion clock > > u_char MotionSpeed ; // Motion speed > > u_char CurrentFrame ; // Current frame being displayed > > u_char NumFrames ; // Total number of frames > > u_char State ; // State of the sprite (Dead, Alive...) > > u_char Hits ; // How many hits the sprite has got > > u_char Doing ; // What the sprite is doing > > u_char Type ; // What kind of sprite is > > // being processed > > // Other sprite related variables.... > >} Sprite, *SpritePtr ; > > > >Sprite PlayerOne [1] ; // Ugly struct of player one that > > // I must use to make my program run > > // using PlayerOne as a pointer > > > >// SpritePtr PlayerOne ; // Right pointer def that it's not usable > >// Sprite *PlayerOne ; // Eh,eh too easy to be able to use this > > I think I see your original problem. Defining a *pointer* to a type, does > not allocate space for the type itself. When you do the following > > SpritePtr PlayerOne; > > You have allocated space for a POINTER to a structure. Not the structure > itself. You can't use this pointer until you tell it to point to something > (a SpriteType structure). So how do you make space for a SpriteType > structure? There are two ways. Ok maybe you got my in this way because usually I use dynamic memory allocation but in a game for a console I think it's not necessary 'cause you have a "rigid" environment and you have to make all fit in your memory so if in the worse case you have fourthy structure on line you must have enought memory for all the structure.(It's true or I'm wrong?) So I have tought that the compiler allocate a static piece of memory alone without I have to tell it. But I don't understand why the Sprite *PlayerOne def is wrong, yet. It should work without malloc, I'm sure I have use something like it in other programs and it should work. I have to malloc also in this way? Please now tell me something about the debugger (that is the REAL problem) where are gone my globals? I can't see them in any debugger's window (As I have already written I can see only some look up tables and two or three variables) Cheers, Giulio