[LC++]question about far *t

Mark Phillips mark at austrics.com.au
Tue Jul 24 17:52:04 UTC 2001


gosh larous wrote:

> Hi. I have written a function in C under borland C++.  I define a function
> as: double far *ghd(.....) and in the body of the function I returned a
> pointer:
>
> double  *ghd(....)
> {
> double str[50];
> ........
> ........
> return(str);
> }

This won't work I suspect, because the variable "str" will disappear
as soon as the function exits!  So you are returning a pointer to a
soon-to-be-non-existant object.  A better way to do it is as
follows:

double *ghd(....) {
double* dPtr=new double[50];
........
........
return dPtr;
}

or something like that.

Cheers,

Mark.



More information about the tuxCPProgramming mailing list