title: How come you can't have multiple decl-specifier-seq's in a declaration?
body: <p>The following is invalid code:</p>
  
  <pre><code>int i = 0, double j = 2.0;
  </code></pre>
  
  <p>The draft standard says why:</p>
  
  <blockquote>
    <p>[N4140/7.1.6]</p>
    
    <p><code>2</code> As a general rule, at most one <em>type-specifier</em> is allowed in the
    complete <em>decl-specifier-seq</em> of a declaration or in a
    <em>type-specifier-seq</em> or <em>trailing-type-specifier-seq</em>. The only exceptions to this rule are the following:</p>
    
    <blockquote>
      <p>— <code>const</code> can be combined with any type specifier except itself.</p>
      
      <p>— <code>volatile</code> can be combined with any type specifier except itself.</p>
      
      <p>— <code>signed</code> or <code>unsigned</code> can be combined with <code>char</code>, <code>long</code>, <code>short</code>,
      or <code>int</code>.</p>
      
      <p>— <code>short</code> or <code>long</code> can be combined with <code>int</code>.</p>
      
      <p>— <code>long</code> can be combined with <code>double</code>.</p>
      
      <p>— <code>long</code> can be combined with <code>long</code>.</p>
    </blockquote>
  </blockquote>
  
  <p>Yes, it prevents something silly like <code>int int</code>, but I don't see anything wrong with the invalid code posted above. Quoting <code>[N4140/7]</code>, a <em>simple-declaration</em> consists of a <em>decl-specifier-seq<sub>opt</sub> init-declarator-list<sub>opt</sub>;</em> </p>
  
  <p><code>[N4140/8]</code> then shows that an <em>init-declarator-list</em> consists of an <em>init-declarator-list</em> , <em>init-declarator</em>,</p>
  
  <p>and an <em>init-declarator</em> is a <em>declarator initializer<sub>opt</sub></em>. </p>
  
  <p>Since we're concerned with only syntax of the form <code>int i = 0</code>, then the <em>declarator</em> we care about is a <em>ptr-declarator</em>, which is a <em>noptr-declarator</em>, which is a <em>declarator-id attribute-specifier-seq<sub>opt</sub></em> and finally a <em>declarator-id</em> consists of merely <code>...</code><sub>opt</sub> <em>id-expression</em>. </p>
  
  <p>For completeness, <code>[N4140/5.1.1]</code> says an <em>id-expression</em> can be an <em>unqualified-id</em>, or simply an <em>identifier</em>.</p>
  
  <p>If I haven't tripped up so far, this is what the grammar reflects.</p>
  
  <p><code>int</code> <em>decl-specifier-seq</em></p>
  
  <p><code>i</code> <em>unqualified-id</em></p>
  
  <p><code>= 0</code> <em>initializer</em></p>
  
  <p><code>int i = 0</code> <em>init-declarator</em></p>
  
  <p>Since the <em>simple-declaration</em> has the <em>decl-specifier-seq</em>, only one <em>decl-specifier-seq</em> applies to the entire <em>init-declarator-list</em>. </p>
  
  <p>Funnily enough, that means you can't do something like this:</p>
  
  <pre><code>int i, const j;
  </code></pre>
  
  <p>Yet:</p>
  
  <pre><code>int i, * j;
  </code></pre>
  
  <p>is perfectly legal because the star is part of a <em>ptr-operator</em>. But you can't do this:</p>
  
  <pre><code>int i, const * j; // pointer to const int
  </code></pre>
  
  <p>This means in the following code that <code>i</code> becomes a pointer to const int. Surprise!</p>
  
  <pre><code>int h = 25;
  int const * j, * i = &amp;h;
  *i = 50; // error: assignment of read-only location '* i'
  </code></pre>
  
  <p>The intent is clear in <code>[N4140/8]</code> with:</p>
  
  <blockquote>
    <p><code>3</code> Each <em>init-declarator</em> in a declaration is analyzed separately as
    if it was in a declaration by itself.<sup>99</sup></p>
    
    <p>99) A declaration with several declarators is usually equivalent to
    the corresponding sequence of declarations each with a single
    declarator. That is</p>
  
  <pre><code>T D1, D2, ... Dn;
  </code></pre>
    
    <p>is usually equivalent to</p>
  
  <pre><code>T D1; T D2; ... T Dn;
  </code></pre>
  </blockquote>
  
  <p>The question is why is it this way?</p>
  
  <hr />
  
  <p>If it was legal, you could do it in for loops, which is somewhat useful.</p>