From: "Andrew Davidson" Newsgroups: comp.os.msdos.djgpp Subject: Re: How does DJGPP store its structs? Date: Wed, 31 Mar 1999 23:51:04 +0100 Organization: Customer of Planet Online Message-ID: <7du8tc$23a$1@news7.svr.pol.co.uk> References: <7ds34s$mpf$1 AT news7 DOT svr DOT pol DOT co DOT uk> <7ds5da$9sq AT sjx-ixn5 DOT ix DOT netcom DOT com> <7dse20$rp8$1 AT news7 DOT svr DOT pol DOT co DOT uk> <7dss2u$ke1 AT dfw-ixnews11 DOT ix DOT netcom DOT com> NNTP-Posting-Host: modem-77.cook.dialup.pol.co.uk X-Trace: news7.svr.pol.co.uk 922920684 2154 62.136.127.205 (31 Mar 1999 22:51:24 GMT) NNTP-Posting-Date: 31 Mar 1999 22:51:24 GMT X-Complaints-To: abuse AT theplanet DOT net X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 Lines: 42 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Marp wrote in message news:7dss2u$ke1 AT dfw-ixnews11 DOT ix DOT netcom DOT com... > Andrew Davidson wrote in message > news:7dse20$rp8$1 AT news7 DOT svr DOT pol DOT co DOT uk... > > > > mainstruct *mystruct; > > unsigned long *test; > > > > test=(unsigned long *)malloc(4); > > // this will crash it with a sigsegv > > mystruct->doublepair1->dp=test; > > Did you get a warning about uninitialized variables when you compiled???? > You forgot to initalize mystruct and doublepair1. You can't assume DJGPP (or > any other compiler) will do that for you. You must do that first to access > members. Try this: > > mainstruct *mystruct; > unsigned long *test; > > test=(unsigned long *)malloc(4); > /* adding these two lines will stop it from crashing */ > mystruct = (mainstruct *)malloc(sizeof(mainstruct)); > mystruct -> doublepair1 = (dpair *)malloc(sizeof(dpair)); > > mystruct->doublepair1->dp=test; Okay... but that far I (eventually) managed to work out for myself. Now what if I want to do: mystruct->doublepair1->p->ph->b->l=test; Anything accessing any structures below dp seems to crash. I've tried mallocing memory for all these pointers but no joy... I can only assume I'm not mallocing the right stuff. Any hints? Andrew