Const correctness for array pointers?
<p>Someone made an argument saying that in modern C, we should always pass arrays to functions through an array pointer, since array pointers have strong typing. Example:</p>

<pre><code>void func (size_t n, int (*arr)[n]);
...

int array [3];
func(3, &amp;array);
</code></pre>

<p>This sounded like it could potentially be a good idea to prevent all kinds of type-related and array-out-of-bounds bugs. But then it occurred to me I don't know how to apply const correctness to this.</p>

<p>If I do <code>void func (size_t n, const int (*arr)[n])</code> then it is const correct. But then I can no longer pass the array, because of incompatible pointer types. <code>int (*)[3]</code> versus <code>const int (*)[3]</code>. The qualifier belongs to the pointed-at data and not to the pointer itself.</p>

<p>An explicit cast in the caller would ruin the whole idea of increased type safety.</p>

<p>How do I apply const correctness to array pointers passed as parameters? Is it at all possible?</p>

<hr>

<p>EDIT</p>

<p>Just as info, someone said that the idea of passing arrays by pointer like this probably originates from MISRA C++:2008 5-2-12. See for example <a href="http://www.codingstandard.com/rule/4-1-1-ensure-that-a-function-argument-does-not-undergo-an-array-to-pointer-conversion/">PRQA's high integrity C++ standard</a>. </p>