But think it over; don't use const everywhere just because you can do it. Use it only where you are absolutely sure that no modification will be made. Write functions as generally as you can; if the function can have a const overload, make it. However, be aware of local variables and don't start returning const references/pointers to them; local variables are destroyed.
Only one question remains to be answered: when is it best to start implementing const capabilities in a program? The most accurate answer would be "before you start writing a single line." The functions in your head should be born with const correctness. It can be hard at the beginning (especially to not abuse it), but once you get it, it will became second nature, and spare you countless hours of debugging.
If you are still reading these lines that means you have reached the end of this article. Now the challenge begins. Start up your compiler and start using the knowledge amassed here. It won't be a trivial task, but if you ever run into problems you can ask the community at DevHardware Forums at any time.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |