View Single Post
Old Oct 5th, 2005, 2:03 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
The const modifier only tells the compiler that it shouldn't allow you to write code that modifies that value. It's a convention, an agreement between you and the compiler that you are a screw-up, and the compiler is allowed to warn you when you do it. Declaring something const does NOT make it actually write protected (normally; one could build a system that did that, in cooperation with the compiler).

In Tempest's case, he is on an OS that has actually flagged that memory as read-only. Trying to write to it causes a system fault. Had he realized that many modern systems would do that, and realized that it WAS write protected, he could have declared it const so that the compiler would remind him if he forgot. That isn't germane. It isn't that he forgot, it's merely that he was unaware of the restrictions imposed on him by his particular implementation. A declaration like that is not, defacto, write protected. It just is in many implementations.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote