title: How to provide an option to a C library via a macro
body: <p>I have the following source named <code>lcd.c</code>.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "lcd.h"
  
  void print_mode(void)
  {
    printf("%d\n",LCD_MODE);
  }
  </code></pre>
  
  <p>The header <code>lcd.h</code> contains the definition for <code>LCD_MODE</code> as follows.</p>
  
  <pre><code>#ifndef LCD_H
  #define LCD_H
  
  #include "util.h"
  
  #ifndef LCD_MODE
  #define LCD_MODE LCD_MODE_8BIT
  #endif
  
  void print_mode(void);
  
  #endif /* LCD_H */
  </code></pre>
  
  <p>The file <code>util.h</code> contains</p>
  
  <pre><code>#ifndef UTIL_H
  #define UTIL_H
  
  #define LCD_MODE_8BIT 1
  #define LCD_MODE_4BIT 0
  
  #endif /* UTIL_H */
  </code></pre>
  
  <p><code>lcd.c</code> will be compiled separately as part of some library. I want to use it with an application <code>main.c</code> as follows.</p>
  
  <pre><code>#include "util.h"
  #define LCD_MODE LCD_MODE_4BIT
  #include "lcd.h"
  
  int main(void)
  {
    print_mode();
    return 0;
  }
  </code></pre>
  
  <p>The desired outcome is to print <code>0</code> as per the definition of <code>LCD_MODE_4BIT</code> in <code>main.c</code>. However, <code>1</code> is printed because the header file sees that <code>LCD_MODE</code> is not defined during the preprocessing for <code>lcd.c</code>. How should I go about passing the <code>LCD_MODE</code> option to <code>print_mode()</code> through the main application?</p>