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

This assumes that the compiler can actually infer that a const-by-reference isn't modified.

The second we have indirection (function pointers), or a different source file without whole-program-optimization, or a library, these assumptions break down.

Further, the author assumes that the compiler can't benefit from the knowledge that something is const because the const can be cached away. This isn't true, e.g. per ISO9899 6.7.3.5:

If an attempt is made to modify an object defined with a const-qualified type through use of an lvalue with non-const-qualified type, the behavior is undefined. If an attempt is made to refer to an object defined with a volatile-qualified type through use of an lvalue with non-volatile-qualified type, the behavior is undefined.



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

Search: