title: Function call makes const attribute of a struct change its value
body: <p>I'm writing this simple library to deal with int matrices:</p>
  
  <pre><code>#ifndef MATRIX_H_
  #define MATRIX_H_
  
  #include &lt;assert.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  typedef struct Matrix Matrix;
  
  Matrix* newMatrix(const unsigned int rows, const unsigned int columns);
  
  void setElementAt(Matrix* self, const unsigned int row, const unsigned int column, const int value);
  
  int getElementAt(const Matrix* self, const unsigned int row, const unsigned int column);
  
  int getRowsNo(const Matrix* self);
  
  int getColumnsNo(const Matrix* self);
  
  void initMatrix(Matrix* self, int value);
  
  #endif
  </code></pre>
  
  <pre><code>#include "Matrix.h"
  
  struct Matrix {
  
      int* grid;
      const unsigned int rowsNo;
      const unsigned int columnsNo;
  };
  
  Matrix* newMatrix(const unsigned int rowsNo, const unsigned int columnsNo) {
  
      assert(rowsNo &gt; 0 &amp;&amp; columnsNo &gt; 0);
  
      Matrix new = {
  
          .grid = malloc(rowsNo * columnsNo * sizeof(int)),
          .rowsNo = rowsNo,
          .columnsNo = columnsNo
      };
  
      Matrix* self = &amp;new;
  
      return self;
  }
  
  int getRowsNo(const Matrix* self) {
  
      return self-&gt;rowsNo;
  }
  
  int getColumnsNo(const Matrix* self) {
  
      return self-&gt;columnsNo;
  }
  
  int getElementAt(const Matrix* self, const unsigned int row, const unsigned int column) {
  
      assert(row &lt; self-&gt;rowsNo &amp;&amp; column &lt; self-&gt;columnsNo);
  
      return self-&gt;grid[row * self-&gt;rowsNo + column];
  }
  
  void setElementAt(Matrix* self, const unsigned int row, const unsigned int column, const int value) {
  
      assert(row &lt; self-&gt;rowsNo &amp;&amp; column &lt; self-&gt;columnsNo);
  
      self-&gt;grid[row * self-&gt;rowsNo + column] = value;
  }
  
  void initMatrix(Matrix* self, int value) {
  
      for(int row = 0; row &lt; self-&gt;rowsNo; row++) {
  
          for(int column = 0; column &lt; self-&gt;columnsNo; column++) {
  
              setElementAt(self, row, column, value);
          }
      }
  }
  </code></pre>
  
  <p>The problem I'm having is that each time that the functions <code>getElementAt()</code> or <code>setElementAt()</code> are invoked, the columnsNo field (and only that one) of the struct Matrix instances changes to a huge random value, despite it being marked as const.
  Which problem am I failing to see here?</p>