Hacker News new | ask | show | jobs
by brigade 4695 days ago
Sorry, I should have been more specific.

C/C++ const has no effect on optimization, unless it's on a global/static object and the compiler can see the original declaration.

I'm not going to look it up in the C++ spec, but in C it's only undefined behavior if the original object was const, and it would make sense for C++ to be the same.

1 comments

It doesn't matter whether it's static or automatic storage duration.