title: Globally increasing constants in C
body: <p>I have a series of global events that are used within a C program in different areas. Any area can create an arbitrary event to hook and handle appropriately.
  I need a way to define a variable amount of arbitrary constants that are unique and global. Sanitation aside, this is approximately what I was hoping would work:</p>
  
  <p>event_handler.h</p>
  
  <pre><code>extern int last_event_ = 0;
  
  #define NEW_EVENT() (last_event_++)
  </code></pre>
  
  <p>first_handler.h</p>
  
  <pre><code>#define FIRST_EVENT NEW_EVENT()
  </code></pre>
  
  <p>second_handler.h</p>
  
  <pre><code>#define SECOND_EVENT NEW_EVENT()
  </code></pre>
  
  <p>main.c</p>
  
  <pre><code>#include "first_handler.h"
  #include "second_handler.h"
  
  int main(int argc, char **argv) {
      printf("Second event number: %d\n", SECOND_EVENT);
      printf("Second event number: %d\n", SECOND_EVENT);
      return 0;
  }
  </code></pre>
  
  <p>This does not work as expected however because of the way macros are executed. Causing it to print out 0 then 1 when it should be printing out the same number.</p>