Results 1 to 4 of 4

Thread: Passing arrays to functions.....

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Posts
    484

    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

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    What do you mean by 'checking'?
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Addicted Member
    Join Date
    Aug 2001
    Location
    I'm mobile
    Posts
    166
    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
    [p r a e t o r i a n]

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width