title: Passing and returning structs by value or by pointer - are there default guidelines?
body: <p>So I've been looking for rule-of-thumb guidelines on two topics:</p>
  
  <ul>
  <li>When to <strong>return</strong> a struct by value, vs. when to return it by pointer (in the case where the called function has created the struct). E.g:</li>
  </ul>
  
  <pre class="lang-c prettyprint-override"><code>MyThing make_my_thing() { MyThing m; /* ... */ ; return m; }
  // Vs.
  MyThing* make_my_thing() { MyThing* m = malloc(sizeof(MyThing)); /* ... */ ; return m; }
  </code></pre>
  
  <ul>
  <li>When to <strong>pass</strong> a struct by value, vs. when to pass it by pointer</li>
  </ul>
  
  <pre class="lang-c prettyprint-override"><code>// Assume do_something() doesn't need to mutate m
  void do_something(MyThing m) { /* ... */ }  
  // Vs.
  void do_something(MyThing* m) { /* ... */ }
  </code></pre>
  
  <p>The rule-of-thumb I'm looking for isn't supposed to fit all cases, but should be the default I'm going with in a general case, where the struct isn't very big.</p>
  
  <p>Please note I'm aware different cases may require different solutions - but nonetheless am looking for a basic 'default' convention most developers follow, if one exists.</p>
  
  <p>I have read many questions and answers on this site, and have come up with the following guidelines:</p>
  
  <ul>
  <li>Default is to <strong>return a struct by value</strong>. Otherwise, we'd have to <code>malloc</code> it and mess with its lifecycle management.</li>
  <li>Default is to <strong>pass a struct by pointer</strong> - no need to worry about lifecycle management any more than we already are, and no unnecessary copying of data.</li>
  </ul>
  
  <p>Are these guidelines widely accepted among C programmers? If not, what would be the more generally accepted conventions?</p>