Click here to Skip to main content
15,891,761 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: char * - returning address of local variable or temporary Pin
Alain Rist8-Nov-10 5:23
Alain Rist8-Nov-10 5:23 
GeneralRe: char * - returning address of local variable or temporary Pin
piul8-Nov-10 5:29
piul8-Nov-10 5:29 
GeneralRe: char * - returning address of local variable or temporary Pin
Alain Rist8-Nov-10 5:59
Alain Rist8-Nov-10 5:59 
AnswerRe: char * - returning address of local variable or temporary Pin
jschell8-Nov-10 5:39
jschell8-Nov-10 5:39 
AnswerRe: char * - returning address of local variable or temporary Pin
David Crow8-Nov-10 5:40
David Crow8-Nov-10 5:40 
AnswerRe: char * - returning address of local variable or temporary Pin
Sauro Viti8-Nov-10 5:50
professionalSauro Viti8-Nov-10 5:50 
AnswerRe: char * - returning address of local variable or temporary Pin
«_Superman_»8-Nov-10 7:03
professional«_Superman_»8-Nov-10 7:03 
AnswerRe: char * - returning address of local variable or temporary Pin
tom144312-Nov-10 2:26
tom144312-Nov-10 2:26 
sRet is a local variable allocated on the stack and as such the memory it uses will be reclaimed when Func returns. That means the stuff it points to will probably not contain what you think it does at some point in the future.

So you have essentially 2 choices:

1. Use void Func (char * sT, char * sRet) as you suggest. Func would then copy the string into the memory supplied by the caller. That memory of course has its own lifecycle.

2. Allocate memory in Func(). For example in C++:

char * Func (char * sT)
{
char * sRet = NULL;

sRet = new char[MAX_STR_SIZE];

if (sRet)
strcpy (sRet, sT);

return sRet;
}

In this case someone has to deallocate the newed up memory later. So for example:
void Foo(void)
{
char *mystr = Func("test");

DoSomethingInteresting(mystr);

delete mystr [];
}
Questionedit control not responding in a dialog created within an activex control Pin
lakshman rao8-Nov-10 2:59
lakshman rao8-Nov-10 2:59 
QuestionRe: edit control not responding in a dialog created within an activex control Pin
David Crow8-Nov-10 3:36
David Crow8-Nov-10 3:36 
AnswerRe: edit control not responding in a dialog created within an activex control Pin
lakshman rao8-Nov-10 3:48
lakshman rao8-Nov-10 3:48 
QuestionRe: edit control not responding in a dialog created within an activex control Pin
David Crow8-Nov-10 3:51
David Crow8-Nov-10 3:51 
AnswerRe: edit control not responding in a dialog created within an activex control Pin
lakshman rao8-Nov-10 3:55
lakshman rao8-Nov-10 3:55 
GeneralRe: edit control not responding in a dialog created within an activex control Pin
lakshman rao18-Nov-10 23:47
lakshman rao18-Nov-10 23:47 
QuestionTranslate C-Code to Csharp Pin
djfresh8-Nov-10 2:16
djfresh8-Nov-10 2:16 
AnswerRe: Translate C-Code to Csharp Pin
Sauro Viti8-Nov-10 2:24
professionalSauro Viti8-Nov-10 2:24 
GeneralRe: Translate C-Code to Csharp Pin
djfresh8-Nov-10 2:51
djfresh8-Nov-10 2:51 
GeneralRe: Translate C-Code to Csharp Pin
Sauro Viti8-Nov-10 3:31
professionalSauro Viti8-Nov-10 3:31 
GeneralRe: Translate C-Code to Csharp Pin
djfresh8-Nov-10 3:47
djfresh8-Nov-10 3:47 
AnswerRe: Translate C-Code to Csharp Pin
Sauro Viti8-Nov-10 4:07
professionalSauro Viti8-Nov-10 4:07 
GeneralRe: Translate C-Code to Csharp Pin
djfresh9-Nov-10 2:12
djfresh9-Nov-10 2:12 
AnswerRe: Translate C-Code to Csharp Pin
Luc Pattyn8-Nov-10 4:07
sitebuilderLuc Pattyn8-Nov-10 4:07 
QuestionWhy SampleGrabber->SetOneShot(FALSE) fails with video files? Pin
Chesnokov Yuriy8-Nov-10 0:12
professionalChesnokov Yuriy8-Nov-10 0:12 
Question890817 - what's wrong with clicking on a control in a dockable pane? Pin
ilostmyid28-Nov-10 0:02
professionalilostmyid28-Nov-10 0:02 
AnswerRe: 890817 - what's wrong with clicking on a control in a dockable pane? Pin
Sauro Viti8-Nov-10 1:04
professionalSauro Viti8-Nov-10 1:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.