X-Originating-IP: [200.34.143.5] From: "J. L." To: References: Subject: Re: Alocating Memory to a Referenced Pointer! Date: Fri, 12 Jul 2002 11:11:01 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Message-ID: X-OriginalArrivalTime: 12 Jul 2002 16:11:16.0175 (UTC) FILETIME=[C0031DF0:01C229BE] Reply-To: djgpp AT delorie DOT com ----- Original Message ----- From: "raelenekelly1" Newsgroups: comp.os.msdos.djgpp To: Sent: Thursday, July 11, 2002 9:34 PM Subject: Alocating Memory to a Referenced Pointer! > Hi all.. > > Myself and a few other posts on this newsgroup in the past have > had trouble allocating memory to a pointer passed by reference. > > reference: > ->'graphics programming: need help with debugging; 8/7/02 post > ->and my 3d engine > both become unstable if you use external functions to allocate memory! > > e.g. > > int F_Allocate_Mem(char *v_string) ^^^ > { > v_string=(char *) malloc (200 *sizeof(char)); > }; No sense in declaring function as returning int, if function return any thing! You can try instead char *F_Allocate_Mem(void){ char *t; t=(char *)malloc (200 *sizeof(char)); if (t==NULL){ perror("Memory exhausted"); exit(1); } return p; } > void main () > { You must use the form int main(void) { because void main is deprecated. Your compiler must emit a message like: "Warning: return tyoe of 'main' is not 'int' > char * BigStringVariable; > int response; No sense, as I say before. > response=F_Allocate_Mem(&BigStringVariable); BigStringVariable=F_Allocate_Mem(); > exit(0); return 0; }; > [snip] > ....MickyDe Regards J. L.