Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You don't <em>need</em> to use the underline, it's just a convention to separate the header name and extension. You cannot use the literal <code>.</code> since that's not valid in an identifier so you replace it with an underscore which is valid.</p> <p>The reason you actually do it is as an include guard. The entire contents of the file are something like:</p> <pre><code>#ifndef PENCERE_H #define PENCERE_H // Your stuff goes here. #endif </code></pre> <p>so that, if you accidentally include it twice:</p> <pre><code>#include "pencere.h" #include "pencere.h" </code></pre> <p>you won't get everything in it duplicated. The double inclusions are normally more subtle than that - for example, you may include <code>pax.h</code> and <code>diablo.h</code> in <em>your</em> code and <code>pax.h</code> also includes <code>diablo.h</code> for its purposes:</p> <pre><code>main.c: #include "pax.h" #include "diablo.h" // Other stuff pax.h: #ifndef PAX_H #define PAX_H #include "diablo.h" // Other stuff #endif diablo.h: #ifndef DIABLO_H #define DIABLO_H typedef int mytype; #endif </code></pre> <p>In this case, if the include guards weren't there you would try to compile the line <code>typedef int mytype;</code> <em>twice</em> in your program. Once for <code>main.c -&gt; pax.h -&gt; diablo.h</code> and again for <code>main.c -&gt; diablo.h</code>.</p> <p>With the include guards, the pre-processor symbol <code>DIABLO_H</code> is defined when <code>main.c</code> includes <code>diablo.h</code> so the <code>#define</code> and <code>typedef</code> are not processed.</p> <p>This particular mapping of header files to <code>#define</code> names breaks down in the situation where you have <code>dir1/pax.h</code> and <code>dir2/pax.h</code> since they would both use <code>PAX_H</code>. In that case, you can use a scheme like <code>DIR1_PAX_H</code> and <code>DIR2_PAX_H</code> to solve the problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload