typedef'ng a pointer and const
<p>I was looking at an example which showed that why typedef'ng a pointer is a bad practice. The part I didn't understand about the example is that why the compiler wasn't able to catch the problem. I elaborated the example into the following code:</p>

<pre><code>#include &lt;stdio.h&gt;

typedef int *TYPE; 

void set_type(TYPE t) {
    *t = 12;
}

void foo(const TYPE mytype) {   
    set_type(mytype);  // Error expected, but in fact compiles 
}

int main() {   
    TYPE a;
    int b = 10;
    a = &amp;b;
    printf("A is %d\n",*a);
    foo(a);
    printf("A is %d\n",*a);

    return 0;
}
</code></pre>

<p>So, I was able to change the value of <code>a</code>. Even though, the example explained that you would have to do, <code>typedef const int *TYPE</code>, to solve the problem, I dont understand why the compiler was not able to catch the error when I am setting <code>TYPE to be const</code> in the function argument itself. I am sure I am missing something very basic.</p>