Message-Id: <199711091926.OAA12087@delorie.com> From: "sl" To: "DJGPP mailing list" Date: Sun, 09 Nov 97 14:31:41 Reply-To: "sl" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Subject: Re: Program with functions Precedence: bulk On Sun, 9 Nov 1997 18:31:34 +1100 (EST), Brett Porter wrote: >Two options: >1. have something like this: >char *retval; >retval = (char*)malloc(strlen(result)+1); >strcpy( retval,result ); >return retval; > >This will mean that the calling function must later say free(string) where >string is the char* returned from getname. That's a problem because if I use: printf("%s", getname(File::Name)); I have no way of running free() on it. It's inconvient. >2.Have the function as: >void File::getname(BYTE mode,char *result) >{ >... >} > >and don't declare result as a local variable. This will mean that you have >to give the function a string that has already had enough memory allocated >for it. (either by using malloc or having a variable char path[MAXPATH], and >pass path to getname). If you don't send it one big enough, it will most >likely crash. This is doable but still not comfortable.. There has to be a better way.. Doesn't automatic disposing or something exist? Or is there some other programming trick that will work? Gili