| delorie.com/archives/browse.cgi | search |
| X-Originating-IP: | [200.34.143.5] |
| From: | "J. L." <jlsgarrido AT hotmail DOT com> |
| To: | <djgpp AT delorie DOT com> |
| References: | <k7rX8.33294$Hj3 DOT 100060 AT newsfeeds DOT bigpond DOT com> |
| Subject: | Re: Alocating Memory to a Referenced Pointer! |
| Date: | Fri, 12 Jul 2002 11:11:01 -0500 |
| MIME-Version: | 1.0 |
| 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: | <OE55sxf2IH17S2dK7zP0000a718@hotmail.com> |
| X-OriginalArrivalTime: | 12 Jul 2002 16:11:16.0175 (UTC) FILETIME=[C0031DF0:01C229BE] |
| Reply-To: | djgpp AT delorie DOT com |
----- Original Message -----
From: "raelenekelly1" <raelenekelly1 AT bigpond DOT com>
Newsgroups: comp.os.msdos.djgpp
To: <djgpp AT delorie DOT com>
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.
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |