title: Reducing Compiled Code Size Dramatically by Factoring-Out a void Pointer
body: <p>I've recently been developing some embedded software in C for a microcontroller, which only has 2kB of Flash memory. Coming to the end of programming, I've been hitting the code limit. Up until now, I've been increasing the level of compiler optimisation when this happens, retesting and then carrying on happily. However, I recently reached the limit of optimisation and with the addition of the last bit of functionality, ran out of memory again. As a result, I had to get the George Foreman out on my source code and drain some fat.</p>
  
  <p>I messed around with reducing some layers of abstraction here and there, which helped matters slightly but not enough. The next thing I saw was that I had the function prototype</p>
  
  <pre><code>void process_event(Event event, void *data);
  </code></pre>
  
  <p>which takes as its parameters the event to process and a void pointer that <em>can</em> be used to pass additional data to the call. If I didn't need any extra data, I passed <code>NULL</code>. This function was written very early on in the development and I realised that I never used <code>data</code>, so I factored it out. This one change gave me the compiled code size saving I needed (~100 bytes), and I'm wondering <em>why</em>, especially considering I generally passed <code>NULL</code> when <code>process_event</code> was called?</p>