Announcement

Collapse
No announcement yet.

Trouble understanding Pascal function parameters.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble understanding Pascal function parameters.

    I have a quick question, I hope I will not have to resort to registration on some new for me forum...

    I am trying to understand, what parameters exactly do in Pascal functions.

    Code:
    Function do_something(params) : DataTyoe;
    My latest understanding is, that whatever is later (after declaration, in actual code) written in place of parameter, it is used as DATA INPUT ONLY. The only way for data to exit is through "Result :=". Have I understood it correctly? Nowhere I search I find a definite answer.

  • #2
    Function parameters (actually called "arguments") can be used as any other variable. They can be used to send data to the function, but also to get data from it (when using pointers.)

    Comment


    • #3
      Originally posted by RealNC View Post
      Function parameters (actually called "arguments") can be used as any other variable. They can be used to send data to the function, but also to get data from it (when using pointers.)
      And those pointers are the exclusive means of getting data out? They are not to get data in? I have to ask, because when programming in object mode, I got so confused by complexity, and amazing flexibility of the language. It turned out that most of what I learned so far was inaccurate.

      Comment


      • #4
        Originally posted by Hirager View Post
        And those pointers are the exclusive means of getting data out? They are not to get data in?
        They can work both ways. You can pass a pointer that points at data that the function can use as input, and you can pass a pointer that points to memory that the function should put results in. Imagine a function that takes two pointers as arguments: 'src' and 'dest'. The function reads data from the memory pointed to by 'src', converts it (can be anything, maybe an MP3 encoder) and stores the results in the memory pointed to by 'dest'. The return value of the function can then serve to tell the caller how many bytes were converted.

        Or a function can use the same pointer argument for both input and output. For example it reads from it and also writes to it.

        Comment


        • #5
          Originally posted by RealNC View Post
          They can work both ways. You can pass a pointer that points at data that the function can use as input, and you can pass a pointer that points to memory that the function should put results in. Imagine a function that takes two pointers as arguments: 'src' and 'dest'. The function reads data from the memory pointed to by 'src', converts it (can be anything, maybe an MP3 encoder) and stores the results in the memory pointed to by 'dest'. The return value of the function can then serve to tell the caller how many bytes were converted.

          Or a function can use the same pointer argument for both input and output. For example it reads from it and also writes to it.
          Hah, even more flexibility... But thanks to your last sentence all the stuff in my brain fell into right places. Thanks a lot!

          Comment

          Working...
          X