What do you mean "the called subroutine receives a *modifiable* pointer/address
value."? I don't believe that is true. Well, it's true you can do the
following:
foo(int *p) {
p = 0;
}
But (note, I am not a "C programmer", but I think I know it well enough) I'm
fairly certain that if you call it "passing the address of variable 'x'", i.e.
foo(&x), you will neither update 'x' nor it's address.
I suppose I could test this, but haven't done so yet.
________________________________
From: IBM Mainframe Discussion List <[email protected]> on behalf of
Paul Gilmartin <[email protected]>
Sent: Sunday, March 26, 2023 6:14 PM
To: [email protected] <[email protected]>
Subject: Re: ASM call by value
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 [email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN