www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/18/09:41:42

From: Bill Davidson <bdavidson AT ra DOT isisnet DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Pointers, arrays and assignments
Date: Wed, 18 Dec 1996 01:12:30 -0400
Organization: Auracom Internet Services
Lines: 40
Message-ID: <597u60$1r0$1@thor.atcon.com>
References: <32B3AA6F DOT 1302 AT synapse DOT net> <01bbea60$9331e020$23705380 AT maan-m DOT -hamze>
NNTP-Posting-Host: 199.45.83.104
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019