Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The strstr() signature is probably the shortest example / explanation why. To implement strstr(), you have to hack the const away to create the return value.

It seems to me the "hacking" is exactly the side-effect that is wanted. It's like the requirement in Rust to do certain kinds of things in an `unsafe { }` block (or using the `unsafe` package in Go): not that you want the compiler to prevent you from doing things completely, but that you want the compiler to prevent you from doing things by accident.

> One man's const data is another man's mutable data.

Yes; and the point of `const` for function parameters is to make sure that data isn't mutated unexpectedly.



> It seems to me the "hacking" is exactly the side-effect that is wanted.

It is not. It's broken at the surface level. If you passed a pointer that is already const on your side, you get back a non-const pointer back that allows you to write to your const memory.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: