Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • You can't legally cast away the constness of a const variable, and it's undefined whether doing so illegally will force it into memory. Commented Jun 22, 2011 at 15:38
  • Sure you can, whether the result is UB or not is another story. And that is my point, you can't prevent it using const. Commented Jun 22, 2011 at 16:09
  • @Blindy: OK, but your answer says that it forces it into memory, when it doesn't necessarily. It could just as well carry on inlining it where it's used correctly, and ignore any attempt to change it; in fact, that is exactly what my compiler does (at least some of the time). Commented Jun 22, 2011 at 16:18
  • What you can do legally is take the address of a const variable, forcing it into memory. That is something you could prevent with #define. Commented Jun 22, 2011 at 16:20
  • That's another way to break const, sure, but even casting const away should get rid of any inlining you can do. I can't remember where I read it though. Commented Jun 22, 2011 at 16:29