6 ms·
Usually you take a look at the FAQ and read the http://news.ycombinator.com/formatdoc http://news.ycombinator.com/formatdoc page. #include <stdio.h> void
by pietrofmaggi 16y ago
Usually you take a look at the FAQ and read the http://news.ycombinator.com/formatdoc http://news.ycombinator.com/formatdoc page.
#include <stdio.h>
void function(int const * const value)
{
printf ("%d\n", *value);
/* more code */
(*value)++;
/* more code */
++value;
}
int main(int argc, char **argv)
{
int value = 1;
int *pvalue = &value;
function(pvalue);
return 0;
}
$gcc t1.c
t1.c: In function ‘function’:
t1.c:9: error: increment of read-only location
t1.c:13: error: increment of read-only location
BTW: I agree, const is really useful
EDIT: I've recompiled on OSX to correct the error message with the correct lines.