Do you have any C++ question? I will try to answer it.
Even if allocated const the compiler often won't see that (cross TU, too many layers). Also, often it's not actually desirable to have the value be constant for the whole lifetime. It's just for a region of code. Unless I copy the value I cannot make C[++] recognize that.
-
-
Ok, thank you for the example. In this case you can't tell C++ it won't change. The best way is to change your code, so it won't use globals. And if it's member function, you should mark it const.
-
Not using globals doesn't mean the compiler *knows* I'm not. That's kind of my point. Just because I *could* have another pointer the compiler needs to generate slower code. I.e. I don't want less UB, instead I want to add a way to make it UB for pointed to objects to change.
- 7 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.