Re: Returning a CHAR[] from a function
- From: "Pete Delgado" <Peter.Delgado@xxxxxxxxx>
- Date: Mon, 28 Aug 2006 10:44:16 -0400
"Tim" <tnorton@xxxxxxxxxxx> wrote in message
news:1156773731.740360.65920@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LPCTSTR CAutoRunDlg::GetProgramPath(void)
{
char buffer[_MAX_PATH]; //declares maimum path
return buffer;
}
Your function is incorrect. You are returning a pointer to a local variable
which goes out of scope as soon as the function has finished. As Vipin told
you earlier, you could make this variable static in order to allow you to
reference it beyond the scope of the function. Otherwise, what you are
doing is incorrect and will cause your code to fail sooner or later in
mysterious ways -usually in a release build!
As you were told earlier, the better solution is to return an object such as
std::string or CString rather than returning a pointer to a buffer.
-Pete
.
- References:
- Returning a CHAR[] from a function
- From: Tim
- Re: Returning a CHAR[] from a function
- From: Vipin
- Re: Returning a CHAR[] from a function
- From: David Webber
- Re: Returning a CHAR[] from a function
- From: Tim
- Re: Returning a CHAR[] from a function
- From: Ajay Kalra
- Re: Returning a CHAR[] from a function
- From: Tim
- Re: Returning a CHAR[] from a function
- From: Ajay Kalra
- Re: Returning a CHAR[] from a function
- From: Tim
- Returning a CHAR[] from a function
- Prev by Date: Re: serialize a structure (with MFC)?
- Next by Date: Re: Sorting the list control from callback function
- Previous by thread: Re: Returning a CHAR[] from a function
- Next by thread: Re: Returning a CHAR[] from a function
- Index(es):
Relevant Pages
|