title: Is accessing a 2D array as a flat array well-defined?
body: <p>I know the internal representation of a multi-dimensional array is the same as the "flattened" array, but I'm looking here for an answer <em>if</em> (and if yes, <em>how</em> and <em>where</em>) the C standard allows me to do the following. Maybe I missed something, but I couldn't find any paragraph telling me that e.g. <code>int []</code> and <code>int [][]</code> are <em>compatible types</em>.</p>
  
  <p>The concrete background: I did my own "toy" implementation of the <a href="https://en.wikipedia.org/wiki/Lights_Out_(game)" rel="nofollow noreferrer">Lights Out</a> game, and I have the following in my game state structure representing the board:</p>
  
  <pre><code>struct context
  {
      // [...]
      int board[5][5];
      // [...]
  };
  </code></pre>
  
  <p>This is a 2D array of "boolean integers" indicating whether a position is lit or not. As the game is won when all positions are unlit, I do the following to check this:</p>
  
  <pre><code>// parameter is `struct context *ctx`
  
  for (int i = 0; i &lt; 25; ++i)
  {
      if (((int *)ctx-&gt;board)[i])
      {
          won = 0;
          break;
      }
  }
  </code></pre>
  
  <p>Now, this code works, but is it actually <em>well-defined</em> or should I use two nested loops iterating over both dimensions of <code>ctx-&gt;board</code>?</p>