title: Structs and unions: which is better from a performance point of view? Passing the parameter by value or pointer?
body: <p>It's probably a silly question, but it makes me slightly quibble every time I want to "optimize" the passage of heavy arguments (such as structure for example) to a function that just reads them. I hesitate between passing a pointer:</p>
  
  <pre><code>struct Foo
  {
      int x;
      int y;
      int z;
  } Foo;
  
  int sum(struct Foo *foo_struct)
  {
      return foo_struct-&gt;x + foo_struct-&gt;y + foo_struct-&gt;z;
  }
  </code></pre>
  
  <p>Or a constant:</p>
  
  <pre><code>struct Foo
  {
      int x;
      int y;
      int z;
  } Foo;
  
  int sum(const struct Foo foo_struct)
  {
      return foo_struct.x + foo_struct.y + foo_struct.z;
  }
  </code></pre>
  
  <p>The pointers are intended not to copy the data but just to send its address, which costs almost nothing.</p>
  
  <p>For constants, it probably varies between compilers or optimization levels, although I don't know how a constant pass is optimized; if it is, then the compiler probably does a better job than I do.</p>
  
  <p>From a performance point of view only (even if it is negligible in my examples), what is the preferred way of doing things?</p>