Grant Edwards <invalid@invalid.invalid>: > On 2015-11-07, Marko Rauhamaa <ma...@pacujo.net> wrote: >> "const" is a very ineffective tool that clutters the code and forces >> you to sprinkle type casts around your code. > > But it allows the compiler to warn you if you pass a pointer to a > read-only data to a function that expects a pointer to writable data.
Unfortunately, it doesn't: ======================================================================== #include <stdio.h> #include <string.h> int main() { const char name[] = "Tom"; char *p = strstr(name, "Tom"); strcpy(p, "Bob"); printf("name = %s\n", name); return 0; } ======================================================================== $ cc -o prog prog.c $ ./prog Bob No warning. Point is, the consequences of "proper" use of const are so annoying even standard library functions would rather grossly abuse it than tolerate compiler warnings everywhere. Marko -- https://mail.python.org/mailman/listinfo/python-list