|
-
Jan 3rd, 2002, 11:20 PM
#1
Thread Starter
Hyperactive Member
Passing arrays to functions.....
Hi,
I have one question. According to my book it says that placing 'const' in front of the argument of the function generates a compile error if the function attempts to change the arrays' values. Is this only for checking purposes. Coz in some of the functions in my book the 'const' is still used. So i reckon that it's only for checking. Am i right?
thnx
-
Jan 4th, 2002, 06:49 AM
#2
Frenzied Member
What do you mean by 'checking'?
Harry.
"From one thing, know ten thousand things."
-
Jan 4th, 2002, 07:53 AM
#3
Addicted Member
Maybe they do that in your book, only to be sure of not changing the values in the array.....(to be truly certain of that) and to show for the readers a good way of programming.....but maybe you're right
-
Jan 4th, 2002, 12:19 PM
#4
Monday Morning Lunatic
It's also for optimisation purposes.
For example, the compiler may place the argument you supply into ROM, where it CANNOT be changed. Since you specified const, it means you're not planning on changing it.
Everybody wins.
Downside - you can cast the const away but you shouldn't do that unless you absolutely have to because you need to work with other code somebody's written and they haven't used const, but you know it doesn't change it.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
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
|