title: Reusing a C macro in several files
body: <p>I have a few commonly used macros that are universally needed in just about every C file I write. Currently I am copying them into each file I need them in. This is likely a bad idea because I'm eventually going to need to change one of them and then I'll end up with inconsistently defined macros between files.</p>
  
  <p>Is there a way to essentially make a header file for macros? I tried to make a header with all my macros in it and include that, but I still get compiler warnings. </p>
  
  <p>UPDATE: 
  The specific warnings I get are implicit declarations of functions such as V4 from the second example.</p>
  
  <p>An example:</p>
  
  <p>file1.c:</p>
  
  <pre><code>#define COMMON_NUMBER 1
  </code></pre>
  
  <p>file2.c:</p>
  
  <pre><code>#define COMMON_NUMBER 1
  
  //...
  </code></pre>
  
  <p>fileN.c:</p>
  
  <pre><code>#define COMMON_NUMBER 1
  
  //Oh wait, it should have been 2 all along..... *facepalm*
  </code></pre>
  
  <p>A better example:</p>
  
  <p>file1.c:</p>
  
  <pre><code>#include "usefulmacros.h"
  
  char* prog;
  int optv;
  
  int main(){
    prog = strdup(argv[0]);    
    optv = 4;           // This would be parsed from # of "-v" in argv[]
    return 0;
  }
  
  void functionA(){
    int dumberror = 1;
    V4("This is a fairly verbose error: %d",dumberror);
  }
  </code></pre>
  
  <p>file2.c:</p>
  
  <pre><code>#include "usefulmacros.h"
  extern char* prog;
  extern int   optv;
  
  void functionB(){
    int differror = 2;
    V4("This is a different error: %d",differror);
  }
  </code></pre>
  
  <p>usefulmacros.h:</p>
  
  <pre><code>#ifndef USEFULMACROS
  #define V4(str, ...) if(optv &gt;= 4){printf("%s: "str,prog,__VA_ARGS__);}
  #endif
  </code></pre>