title: How much does the C standard library extensibility affect C++ programs?
body: <p>Take this code:</p>
  
  <pre><code>int issuecode(int i)
  {
    return 2 * i;
  }
  
  int main(int argc, char **argv)
  {
    return issuecode(argc);
  }
  </code></pre>
  
  <p>The way I understand it, if compiled as a C program, it will have undefined behaviour. I reason based on these standard quotes:</p>
  
  <p><strong>C99, 7.26</strong> (or C11, 7.31)</p>
  
  <blockquote>
    <p>The following names are grouped under individual headers for convenience. All external names described below are reserved no matter what headers are included by the program.</p>
  </blockquote>
  
  <p><strong>C99, 7.26.2</strong> (or C11, 7.31.2)</p>
  
  <blockquote>
    <p>Function names that begin with either <code>is</code> or <code>to</code>, and a lowercase letter may be added to the declarations in the <code>&lt;ctype.h&gt;</code> header.</p>
  </blockquote>
  
  <p><strong>C99, 7.1.3</strong> (or C11, 7.1.3)</p>
  
  <blockquote>
    <ol>
    <li><p>Each header declares or defines all identifiers listed in its associated subclause, and optionally declares or defines identifiers listed in its associated future library directions subclause and identifiers which are always reserved either for any use or for use as file scope identifiers.</p>
    
    <p>[...]</p>
    
    <ul>
    <li>All identifiers with external linkage in any of the following subclauses (including the future library directions) are always reserved for use as identifiers with external linkage.</li>
    </ul></li>
    <li><p>[...] If the program declares or defines an identifier in a context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved identifier as a macro name, the behavior is undefined.</p></li>
    </ol>
  </blockquote>
  
  <p>Based on the above, I believe the function name <code>issuecode</code> is actually reserved for use in <code>&lt;ctype.h&gt;</code>, and so the program technically has UB.</p>
  
  <p><strong>Question 0</strong> (sanity check): Is my reading of the standard correct and the program's behaviour technically undefined?</p>
  
  <p><strong>Question 1:</strong> Will the program have UB if compiled as C++ code?</p>
  
  <p>I believe the answer is "no," as from the following quotes, I'd say the "future library directions" of C are not part of the C++ standard library, but I am not really sure.</p>
  
  <p><strong>C++11, 21.7</strong></p>
  
  <blockquote>
    <ol>
    <li><p>Tables 74, 75, 76, 77, 78, and 79 describe headers <code>&lt;cctype&gt;</code>, <code>&lt;cwctype&gt;</code>, <code>&lt;cstring&gt;</code>, <code>&lt;cwchar&gt;</code>, <code>&lt;cstdlib&gt;</code> (character conversions), and <code>&lt;cuchar&gt;</code>, respectively.</p></li>
    <li><p>The contents of these headers shall be the same as the Standard C Library headers <code>&lt;ctype.h&gt;</code>, <code>&lt;wctype.h&gt;</code>, <code>&lt;string.h&gt;</code>, <code>&lt;wchar.h&gt;</code>, and <code>&lt;stdlib.h&gt;</code> and the C Unicode TR header , respectively, with the following modifications:</p></li>
    </ol>
  </blockquote>
  
  <p>None of the "following modifications" mentions the additional reserved identifiers. Table 74 is a taxative list of function names like <code>isdigit</code> and <code>isalnum</code>.</p>
  
  <p><strong>C++11, C.2</strong></p>
  
  <blockquote>
    <p>1. This subclause summarizes the contents of the C++ standard library included from the Standard C library. It also summarizes the explicit changes in definitions, declarations, or behavior from the Standard C library noted in other subclauses (17.6.1.2, 18.2, 21.7).</p>
    
    <p>7. The C++ standard library provides 209 standard functions from the C library, as shown in Table 153.</p>
  </blockquote>
  
  <p>Again, table 153 is a taxative list.</p>
  
  <p><strong>Question 2:</strong> Assuming I am wrong on question 1 and the program actually does have UB in C++ as well, would the following change affect this?</p>
  
  <pre><code>namespace foo {
  
    int issuecode(int i)
    {
      return 2 * i;
    }
  
  }
  
  using namespace foo;
  
  int main(int argc, char **argv)
  {
    return issuecode(argc);
  }
  </code></pre>
  
  <hr>
  
  <p><em>Note:</em> The standard quotes are taken from drafts N1256 (C99), N1570 (C11) and N3242 (C++11), which are the latest publically available drafts for the respective language versions.</p>