Results 1 to 5 of 5

Thread: Trouble understanding Pascal function parameters.

  1. #1
    Join Date
    Oct 2011
    Location
    Toruń, Poland
    Posts
    160

    Default 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. #2
    Join Date
    Jul 2008
    Location
    Greece
    Posts
    3,790

    Default

    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.)

  3. #3
    Join Date
    Oct 2011
    Location
    Toruń, Poland
    Posts
    160

    Default

    Quote 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.

  4. #4
    Join Date
    Jul 2008
    Location
    Greece
    Posts
    3,790

    Default

    Quote 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.

  5. #5
    Join Date
    Oct 2011
    Location
    Toruń, Poland
    Posts
    160

    Default

    Quote 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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •