AnsweredAssumed Answered

Overwrited variable

Question asked by Martin Dusek on Apr 17, 2009
Latest reply on Apr 19, 2009 by Martin Dusek

Hello,

in main function, I declare a pointer called MY_VAR. It points to type called TYPE, it is a structure. In function called from main function there is set a variable of type TYPE and the function returns the address of this variable. But if my program continues, another call of some function destroys the data stored on address where MY_VAR pointer points. How to tell the compiler not to destroy the data in *MY_VAR?

 


void main(void) {  TYPE *MY_VAR;  MY_VAR = setFunction();  anotherFunction(); // it destroys data in *MY_VAR}TYPE *setFunction() {  TYPE result;  // result = ......  return &result;}

Outcomes