This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: problems with char * return from a function


On Wed, Jun 11, 2008 at 08:52:13PM -0400, Vardhan, Sundara (GE Infra, Energy) wrote:
> Hi All
> 
> I am calling a function x within strcpy as follows
> 
> strcpy(a,x("sample text","default text"));
> 
> x is defined as follows
> 
> char * x(char *m, char *n)
> {
> 	char *return_val=NULL;
> 	if (check m is in database)
> 		return_val=m;
> 	else
> 		return_val=n;
> 	return(return_val);
> }

I see no problem with this code and writing a testcase based on it works
for me.  I think your problem is elsewhere.  Can you boil this down to a
self-contained program, including main() and everything, that exhibits
the incorrect behavior, which we can compile and test ourselves?  If
this does not reveal your bug, please post it with the version of GCC
you are using as well.

Thanks,
Dan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]