L
lovecreatesbea...
C stops the conversion from (char **) to (const char **). c-faq.com
sec 11.10 has explanation on this point. But, for example, even the
conversion from (char *) to (const char *) brings the same dangerous
as in the previous conversion. Why the latter simple but dangerous one
is allowed in C?
$ cat f1.c
int main(void)
{
const char c = 'a';
char *p;
const char *cp = p;
cp = &c;
*p = 'x'; /*line 8*/
return 0;
}
$ cc -Aa -g f1.c
$ ./a.out
Bus error(coredump)
$ gdb -q ./a.out core
Core was generated by `a.out'.
Program terminated with signal 10, Bus error.
warning: The shared libraries were not privately mapped; setting a
breakpoint in a shared library will not work until you rerun the
program.
#0 0x29d4 in main () at f1.c:8
8 *p = 'x';
(gdb) quit
$
sec 11.10 has explanation on this point. But, for example, even the
conversion from (char *) to (const char *) brings the same dangerous
as in the previous conversion. Why the latter simple but dangerous one
is allowed in C?
$ cat f1.c
int main(void)
{
const char c = 'a';
char *p;
const char *cp = p;
cp = &c;
*p = 'x'; /*line 8*/
return 0;
}
$ cc -Aa -g f1.c
$ ./a.out
Bus error(coredump)
$ gdb -q ./a.out core
Core was generated by `a.out'.
Program terminated with signal 10, Bus error.
warning: The shared libraries were not privately mapped; setting a
breakpoint in a shared library will not work until you rerun the
program.
#0 0x29d4 in main () at f1.c:8
8 *p = 'x';
(gdb) quit
$