www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/09/16:38:32

Message-Id: <199711091926.OAA12087@delorie.com>
From: "sl" <SL AT usemail DOT com>
To: "DJGPP mailing list" <djgpp AT delorie DOT com>
Date: Sun, 09 Nov 97 14:31:41
Reply-To: "sl" <SL AT usemail DOT com>
MIME-Version: 1.0
Subject: Re: Program with functions

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

- Raw text -


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