Possible Duplicate:
returning a pointer to a literal (or constant) character array (string)?
Is the code below correct?
const char* state2Str(enum State state)
{
   switch (state)
   {
      case stateStopped: return "START";
      case stateRunning: return "RUNNING";
      default: return "UNKNOWN";
   }
}
printf("State is: %s\n", state2Str(stateRunning));
What worries me is that the function return a pointer to a temporary object. What is the lifetime of such return values? Language is C89.
 
     
     
    