title: Why do C compilers prepend underscores to external names?
body: <p>I've been working in C for so long that the fact that compilers typically add an underscore to the start of an <code>extern</code> is just understood...  However, <a href="https://stackoverflow.com/questions/2627004/embedding-binary-blobs-using-gcc-mingw">another SO question today</a> got me wondering about the real reason why the underscore is added. A <a href="http://en.wikipedia.org/wiki/Underscore#Origins_in_identifiers" rel="noreferrer">wikipedia article</a> claims that a reason is:</p>
  
  <blockquote>
    <p>It was common practice for C compilers to prepend a leading underscore to all external scope program identifiers to avert clashes with contributions from runtime language support</p>
  </blockquote>
  
  <p>I think there's at least a kernel of truth to this, but also it seems to no really answer the question, since if the underscore is added to all externs it won't help much with preventing clashes.</p>
  
  <p>Does anyone have good information on the rationale for the leading underscore?</p>
  
  <p>Is the added underscore part of the reason that the Unix <code>creat()</code> system call doesn't end with an 'e'? I've heard that early linkers on some platforms had a limit of 6 characters for names.  If that's the case, then prepending an underscore to external names would seem to be a downright crazy idea (now I only have 5 characters to play with...).</p>