This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: problems with char * return from a function
- From: Dan Hipschman <dsh at linux dot ucla dot edu>
- To: "Vardhan, Sundara (GE Infra, Energy)" <sundara dot vardhan at ge dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 11 Jun 2008 23:00:33 -0700
- Subject: Re: problems with char * return from a function
- References: <8E460D1B58F94945A20AA70D4D41430D052DE9BF@ALPMLVEM08.e2k.ad.ge.com>
- Reply-to: dsh at linux dot ucla dot edu
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