Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
kevincox
on July 12, 2023
|
parent
|
context
|
favorite
| on:
Breaking java.lang.String
I haven't done much C++ in a few years but IIRC you can remove const as long as the "original" value isn't const. So `const_cast((*const Foo)foo)` is fine if foo is not const.
erik_seaberg
on July 12, 2023
[–]
Isn’t the linker entitled to put a constant object in a read-only page of the binary if it doesn’t require a ctor at runtime?
kevincox
on July 12, 2023
|
parent
[–]
Yes. That is why global static `const`s (with exceptions like if they have mutable fields) can't legally have their `const` casted away.
Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: