user18795: I'd like to define a function such that I return a string and a boolean indicating whether the result is valid. Like this:
bool getStringOrTimeout(String *s) {
  ...
  if (timed_out) {
    return false;
  } else {
    *s = String(<some value>);
    return true;
  }
}

Is this going to cause a memory problem because the string is allocated on the stack and deallocated when it leaves scope, or is this okay?

user10794: You are better off passing the string by reference, like this:
bool getStringOrTimeout(String & s)
{
  if (timed_out)
    return false;
  s = "foo";
  return true;

}

That means the caller's string will be modified. And you no longer need to pass down a pointer to a string.

18795: <p>I'd like to define a function such that I return a string and a boolean indicating whether the result is valid. Like this:</p>

<pre><code>bool getStringOrTimeout(String *s) {
  ...
  if (timed_out) {
    return false;
  } else {
    *s = String(&lt;some value&gt;);
    return true;
  }
}
</code></pre>

<p>Is this going to cause a memory problem because the string is allocated on the stack and deallocated when it leaves scope, or is this okay?</p>
 10794: <p>You are better off passing the string by reference, like this:</p>

<pre><code>bool getStringOrTimeout(String &amp; s)
{
  if (timed_out)
    return false;
  s = "foo";
  return true;

}
</code></pre>

<p>That means the <em>caller's</em> string will be modified. And you no longer need to pass down a pointer to a string.</p>
