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

Probably not, given the possibility that they can be const_casted back into mutable values. Locating static const values in read-only pages would result in crashes from valid statements in the language. In other words if you put a static const in a read only page, it would probably be considered a bug in your linker.


That doesn't rhyme with my understanding of C++ (which is limited, of course). This sounds like undefined.


Aren't they put into the .rodata section of the binary?

Crashing is exactly what happens, thankfully

https://godbolt.org/z/vKj9dcPMc


Generally yes, if you have a bunch of const data in your C++ code, it will go in .rodata. Depending on the compiler/flags/optimizations, of course. https://stackoverflow.com/a/44938843




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

Search: