Mail Archives: djgpp/1996/12/18/09:41:42
Hi:
Maan M. Hamze wrote:
>
> Bill Lachance <billl AT synapse DOT net> wrote in article
> <32B3AA6F DOT 1302 AT synapse DOT net>...
> >But when I try a stunt like:
> > plyr[0]->X=4960, the program crashes abruptly (I've isolated the
> > problem).
> >
> > Am I breaking some unknown rule here?
> >
> Hi Bill
[snip]
> You are not setting your pointer to an address before dereferencing it.
[snip]
> Pointer Golden Rule: ALWAYS set a pointer to a definite and appropriate address before applying the
> dereferencing operator (*) to it.(page 127).
Just to reiterate, you have declared something like
struct player *players[3];
So "players" is an array of pointers to struct player; great, you have
the pointers, but you haven't allocated the actual structures and
associated them with the pointers. So you have an array of pointers to
struct player that contain garbage (the pointers do; the structures
don't exist). You need to allocate the structures and store the
addresses in the array of pointers.
I think this is why people like C++ (and even *eek* java)!
> Maan M. Hamze
> mmhamze AT mail DOT utexas DOT edu
> http://leb.net/~mmhamze
--
+---------------------------------------+
| Bill Davidson |
| bdavidson AT ra DOT isisnet DOT com |
| http://www.isisnet.com/bdavidson/ |
+---------------------------------------+
- Raw text -