title: If-statement vs function pointer
body: <p>The goal is to change the behaviour in an event loop, depending on whether a checkbox is toggled on or off. The simplest way, that I can think of, is just to test the checkbox state each time the loop is run. </p>
  
  <pre><code>// if-statement
  
  void action() { /* ... */ }
  
  
  void someLoop() {
  
    if (checkboxTrue) {
      action();
    }
    // ... other stuff
  
  }
  </code></pre>
  
  <p>Would the code be more performant and cleaner or in any other way better, if a function pointer was being used? Like this: </p>
  
  <pre><code>// function pointer
  
  void action() { /* ... */ }
  void empty() {}
  void (*actionPtr)();
  
  
  void checkboxChanged(int val) {
  
    if (val == 1)
      actionPtr = &amp;realAction;
    else
      actionPtr = &amp;empty;
  
  }
  
  void someLoop() {
  
    (*actionPtr)();
    // ... other stuff
  
  }
  </code></pre>