title: const and typedef of arrays in C
body: <p>In C, it's possible to <code>typedef</code> an array, using this construction :</p>
  
  <p><code>typedef int table_t[N];
  </code></p>
  
  <p>Here, <code>table_t</code> is now defined as an array of N <code>int</code>. Any variable declared such as <code>table_t t;</code> will now behave as a normal array of <code>int</code>. </p>
  
  <p>The point of such construction is to be used as an argument type in a function, such as :</p>
  
  <p><code>int doSomething(table_t t);
  </code></p>
  
  <p>A relatively equivalent function prototype could have been :</p>
  
  <p><code>int doSomething(int* t);
  </code></p>
  
  <p>The merit of the first construction is that it enforces <code>N</code> as the size of the table. In many circumstances, it's safer to enforce this property, rather than relying on the programmer to properly figure out this condition.</p>
  
  <p>Now it's all good, except that, in order to guarantee that the content of table will not be modified, it's necessary to use the <code>const</code> qualifier.</p>
  
  <p>The following statement is relatively simple to understand :</p>
  
  <p><code>int doSomething(const int* t);
  </code></p>
  
  <p>Now, <code>doSomething</code> guarantee that it will not modify the content of the table passed as a pointer.
  Now, what about this almost equivalent construction ? :</p>
  
  <p><code>int doSomething(const table_t t);
  </code></p>
  
  <p>What is <code>const</code> here ? the content of the table, or the pointer to the table ?
  If it's the pointer which is <code>const</code>, is there another way (C90 compatible) to retain the ability to define the size of the table and to tell that its content will be const ?</p>
  
  <p>Note that it's also necessary sometimes to modify the content of the table, so the <code>const</code> property cannot be embedded into the typedef definition.</p>
  
  <p>[<em>Edit</em>] Thanks for the excellent answers received so far.
  To summarize :</p>
  
  <ul>
  <li>The initial assumption of typedef enforcing size <em>N</em> was completely wrong. It basically behaves the same as a normal pointer.</li>
  <li>The <code>const</code> property will also behave the same as if it was a pointer <em>(in stark contrast with a typedef to a pointer type, as underlined by @random below)</em></li>
  <li>To enforce a size (which was not the initial question, but end up being quite important now...), see <a href="https://stackoverflow.com/a/4710472/333698">Jonathan's answer</a> </li>
  </ul>