|
-
November 5th, 2009, 03:29 AM
#7
Re: Question regarding "const"
 Originally Posted by robwong81
Ok so then it seems it has more of a structured usage than an actual needed use. Its main purpose is for maintaining code and working with others who use it in a big project that your a part of. Thanks to all of you for your quick and discerning answers.
Not 100% true. If you are coding on an embedded environment, then your const objects may not be in the same address space as your non-const objects. Also, using const may help your compiler create create more efficient code:
Code:
const int a = 5;
doSomething(a);
print(a);
Look at the above code. Your compiler will be smart enough to know that a will be 5 throughout the program, and won't bother "checking if it really is". If a was not const, your compiler would have to check a after doSomething, just in case doSomething changed a.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|