On Sun, 26 Mar 2023 23:18:49 +0000, Frank Swarbrick wrote:

>True, but "passing by reference" and "passing a 'reference' (pointer/address) 
>by value" are the same.
>
No.  When "passing a 'reference' (pointer/address) by value" the called 
subroutine
receives a *modifiable* pointer/address value.

When "passing by reference" (supported by Pascal but not by C) the called 
routine
receives no such value.
                     
>In COBOL, for example, the following end up doing the same thing.
>
Do not use CO BOL as an exemplar of programming discipline.  Cobol rots the 
brain.

>call 'myfunc' using by reference my-field
>call 'myfunc' using by value address of my-field
>
In the first case, what is the *modifiable* pointer/address object?  Does it 
have a name?

>Both are the same as doing the following in C:
>myfunc(&my_field)
> 
Given suitable preceding declarations, I can do (untested):
    myfunc(&my_field) {
        my_field = your_field;
            ...
        };

A tested example:
    #include <stdio.h>

    int scanit( char *S ) {
        for ( ; *S; ++S ) {  /* "++S modifies a pointer value.  */
        printf( "%c\n", *S );
        };
        return 0; };

    int main( void ) {
        return scanit( "Hello, world!" );
        };

1192 $ make tinyc
cc     tinyc.c   -o tinyc
1193 $ ./tinyc
H
e
l
...

-- 
gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to