title: How to turn "implicit declaration" warnings in $CC into errors?
body: <p>Preamble: My C may be fairly rusty; I first started writing C programs in somewhere around 1993 -- compilers may have been different back then, but I recall that when one attempted to refer to a C function that was not declared, the compiler would abort. This is from memory.</p>
  <p>Currently, I am perplexed as to why GCC (4.4.3) is so forgiving on me when I [intentionally] mismatch or omit declaration of <code>bar</code> below, with its definition in <code>bar.c</code>. Because the compiler does not warn me, the program proceeds to a fatal addressing error at runtime -- since <code>bar</code> wants an address and is given an integer, it ends up de-referencing that integer as an address.</p>
  <p>A strict compiler, or so I would think, would abort on me with an error. Am I missing something? My build command line is as follows:</p>
  <pre><code>cc -o foobar -g -Wall -std=c99 -fexec-charset=ISO-8859-1 -DDEBUG foo.c bar.c
  </code></pre>
  <p>With <code>foo.c</code>:</p>
  <pre><code>int main() {
      int a;
      bar(a);
      return 0;
  }
  </code></pre>
  <p>and <code>bar.c</code>:</p>
  <pre><code>void bar(int * a) {
      *a = 1;
  }
  </code></pre>
  <p>I have intentionally omitted declaration of <code>bar</code> and, as mentioned, intentionally pass it an integer (could be anything really) instead of an address that its actual definition would otherwise mandate. Because <code>$(CC)</code> does not stop me, I end up with a segmentation fault (x86, Ubuntu 10.04). I am aware that a compliant C (C99?) compiler would implicitly create an <code>int bar(void)</code> declaration for <code>bar</code> if none otherwise found, but in this case that's obviously not what I want at all!</p>
  <p>I want to protect myself from the kind of errors -- where I make the human mistake of mismatching declarations and definitions or omitting the former altogether.</p>
  <p>I tried to instead just invoke the compiler without the linking step (with the <code>-c</code> switch) -- but it doesn't matter as compiling still succeeds with warnings. The linker might complain though, but I want <em>the compiler</em> to stop me <em>before</em> that happens.</p>
  <p>I <em>do not</em> actually want to turn all my warnings into errors (e.g. with <code>-Werror</code>), because:</p>
  <ul>
  <li>I could have included the wrong <code>float bar(double a);</code> at the top of <code>foo.c</code>, which would eliminate the warning altogether, but doesn't change the fact that the resulting program crashes; alas, a program that compiles successfully without warnings (even with the <code>-Wall</code> switch) but still is faulty</li>
  <li>I have and will have other types of warnings that should stay warnings and not prevent successfully building the program</li>
  <li>It would be dealing with the effect of the problem, rather than the problem itself</li>
  <li>It's not just the <em>types</em> of warnings, but also particular instances thereof; I wouldn't want to turn a specific warning into an error because in some instances that would not be applicable; this would be too &quot;coarse&quot; of a solution which doesn't take into account the specifics of and the context in which the warning occurred</li>
  </ul>