Sujet : Re: technology discussion → does the world need a "new" C ?
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 19. Aug 2024, 12:29:49
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v9vabe$2rk2q$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
User-Agent : Mozilla Thunderbird
On 19/08/2024 02:30, Ben Bacarisse wrote:
Bart <bc@freeuk.com> writes:
On 19/08/2024 01:01, Ben Bacarisse wrote:
Bart <bc@freeuk.com> writes:
>
>
You or he would have to go into more detail, such as an actual example, to
demonstrate whatever it is that you think is wrong about passing a pointer
argument by-reference.
No one has said any such thing, so I can't see how any more detail could
help. I suspect you've lost track of the point being made.
>
Probably, and perhaps not just me! But I'd still quite like to know exactly
what it is that is marked as 'disallowed'.
I don't know how to explain it any better. If you really want to know,
maybe you could say what /you/ think was incorrectly marked as
disallowed so I can see how you were interpreting the table.
I think I already said that several times!
But I need to use concrete code, and there is no existing mainstream language with pass-by-reference that is simple enough to use for such examples. Except for mine and that is not acceptable here.
So I'll use an extended C where a '&' in front of a parameter's base-type marks it as pass-by-reference.
First an example written in standard C:
#include <stdio.h>
void F(int* p) {
printf("%d\n", *p);
++p;
}
int main(void) {
int A[] = {10,20,30};
int* p = &A[0];
F(p);
printf("%d\n", *p);
}
This passes a normal pointer. The output is 10 10 from both printfs, because the ++p within F does not affect the original pointer in 'main'.
Now the same program, but using pass-by-reference for 'p'; I won't show the whole thing, as the program looks exactly the same except for this line:
void F(&int* p) {
The output should now be 10 20 (as verified using my language; if interested, that is shown below, and below that is the standard C that might be generated by a transpiler from this fantasy C).
So this is passing a pointer, by reference, and it is allowed!
Or maybe, just maybe, Tim said it for good reason.
And yet, he continues to be cagey about it, and you're defending him. Just give me a freakin' example!
WHAT EXACTLY IS IT THAT IS DISALLOWED?
Just saying 'pointer argument' does not cut it.
(I'm sure this is some sort of game he's playing as he does this a lot.
Hinting at something but refusing to give details and suggesting people work it out for themselves.)
-------------------------------
proc F(ref int &p) =
println p^
++p
end
proc main =
static []int A = (10,20,30)
ref int p := &A[1]
F(p)
println p^
end
Shows:
10
20
Equivalent to:
void F(int** p) {
printf("%d\n", **p);
++(*p);
}
int main(void) {
int A[] = {10,20,30};
int* p = &A[0];
F(&p);
printf("%d\n", *p);
}
Also shows 10 20.