title: C Header Based Configuration Not Working as Expected
body: <p>In my C code, I want to have some configurations that can be set prior to including my header file. However, defining it before or after my include in the main source file is always using it with the default value (even if I set it before my include).</p>
  <p>Below are my source files.</p>
  <p><code>header.h</code></p>
  <pre><code>#ifndef header_h
  #define header_h
  
  #ifndef MY_DEBUG
  #  define MY_DEBUG 0
  #endif
  
  void print(int*, int);
  
  #endif /* header_h */
  </code></pre>
  <p><code>header.c</code></p>
  <pre><code>#include &quot;header.h&quot;
  #include &lt;stdio.h&gt;
  
  void print(int* data, int count) {
      if(MY_DEBUG) {
          printf(&quot;List Type: int - Count: %d\n&quot;, count);
      }
  
      printf(&quot;[&quot;);
  
      int i;
      for(i = 0; i &lt; count; ++i) {
          if(i &gt; 0) {
              printf(&quot;, &quot;);
          }
  
          printf(&quot;%d&quot;, data[i]);
      }
  
      printf(&quot;]\n&quot;);
  }
  </code></pre>
  <p><code>main.c</code></p>
  <pre><code>#define MY_DEBUG 1
  
  #include &quot;header.h&quot;
  
  // #define MY_DEBUG 1
  
  int main(int argc, const char** argv) {
      int list[5] = { 1, 2, 3, 4, 5 };
      int count = 5;
  
      print(list, count);
  
      return 0;
  }
  </code></pre>
  <p>The output is always <code>[1, 2, 3, 4, 5]</code>.</p>
  <p>Is this not the correct way to use the configuration in the headers or am I missing something?</p>
  <p>I don't want to pass the defines when compiling, I want to be able to do them using <code>#define</code> in my code.</p>
  <p>EDIT: I tried something now, I guess now I know why it wasn't working. I think it's because my source file, when compiled, before main <code>MY_DEBUG</code> wasn't defined yet so it took the default value. I tried to move the implementation to the header and remove the <code>header.c</code> altogether and it seems to have worked when defining <code>MY_DEBUG</code> before my include. But this is not my case here, is there some kind of workaround for it? Maybe define the configurations as variables in a separate header/source files and have their own getters and setters?</p>