title: How to make global constant (work across multiple files) in C program?
body: <p>I have an ANSI C program comprising two files. The first file contains the <code>main()</code> function, and the second file contains other functions that the first file calls. Before the <code>main()</code> function definition, I've placed the following code:</p>
  
  <pre><code>#define PI 3.14159265358979323846
  </code></pre>
  
  <p>but the 2nd file didn't see this variable. The first file sees it fine. Then, I placed this same line in the second file (while keeping it in the first file as above), before the function definitions, but still the second file doesn't see it. Things always compile fine, but when tracing the variable PI in gdb, it shows <code>"No symbol "PI" in current context."</code></p>
  
  <p>How to make PI a global constant viewable across all files compiled in the application?</p>
  
  <p>EDIT / UPDATE:</p>
  
  <p>Based on the response so far, I've created the following file:</p>
  
  <p><em>myheader.h</em> </p>
  
  <pre><code>#ifndef my_header_stuff
  #define my_header_stuff
      #define PI 3.1415926535897932384626433832795
  #endif
  </code></pre>
  
  <p>and in the two files I want to see this constant PI, I've included this file as follows:</p>
  
  <p><em>file1.c</em></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "myheader.h"
  int main(void) {
    etc...
  }
  </code></pre>
  
  <p>and <em>file2.c</em></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "myheader.h"
  double interesting_function(void) {
    etc...
  }
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li><p>When I use GDB to debug, <code>b PI</code> returns (in both files, same result) "No symbol "PI" in current context". However, the math depending on PI is computed correctly. Is there a way to view PI in gdb?</p></li>
  <li><p>Can I also include the two lines for stdio and stdlib in the <code>myheader.h</code> file?</p></li>
  <li><p>Can I also include any function prototypes in the <code>myheader.h</code> file? If I do, and then let's say I create a file3.c that doesn't require any of these prototypes because it doesn't use those functions, is any harm done?</p></li>
  </ol>