Path: chuka.playstation.co.uk!news From: "Craig Graham" Newsgroups: scee.yaroze.programming.codewarrior Subject: Re: Pointer usage (Was Re: Now I'm getting REALLY mad!) Date: 21 Dec 1997 22:45:38 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 41 Message-ID: <01bd0d9a$48550ce0$8fd449c2@Angela1.intelligent-group.com> 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> <349CED0F.A1B363A0@tin.it> NNTP-Posting-Host: l143.mistral.co.uk X-Newsreader: Microsoft Internet News 4.70.1155 Giulio wrote in article <349CED0F.A1B363A0@tin.it>... > > >// SpritePtr PlayerOne ; // Right pointer def that it's not usable > > >// Sprite *PlayerOne ; // Eh,eh too easy to be able to use this > 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? Nope, Joel was right - the line: Sprite *PlayerOne; should only allocate 4 bytes of storage (sizeof a pointer). It doesn't allocate the structure, only the pointer to a structure of type Sprite. The correct code is: Sprite PlayerOne; Sprite *ptrPlayerOne; main() { ptrPlayerOne=&PlayerOne; } If it was working in other programs, it's a fluke, as you've been using an uninitialised pointer - which will be pointing at a random location in memory. This may sometimes work, but not reliably - change a single line of code and the link map will be different, then your uninitialised pointer may point to some code. You then corrupt the code and your program crashes unpredictably. Anyone who's been using the tutorial code from the University of Middlesex should check for this, as they had that problem in several places - I pointed it out and they've fixed it in their latest tutorials. Craig.