Sujet : Re: technology discussion → does the world need a "new" C ?
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 10. Jul 2024, 17:48:57
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6me1p$205a8$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 23 24
User-Agent : Mozilla Thunderbird
On 10/07/2024 16:54, James Kuyper wrote:
On 10.07.2024 16:49, bart wrote:
...
"So if arrays aren't passed by value in C, and they aren't passed by
reference, then how the hell ARE they passed?!"
The problem with that question is the same as the problem with the
question "How are Justices of the US Supreme Court elected?". They
aren't elected, so the question cannot be answered. Arrays cannot be
passed in C, so the question of how they are passed also cannot be answered.
You can pass a pointer to the start of an array or a pointer to the
whole array; either way,
How is that interestingly different from pass-by-reference?
Which as you know involves a pointer to the value of an object, so the values are not passed, only the value of the pointer.
(You may also know that every language will use pass-by-value for everything if you delve deeply enough.)
In C, if you have this char[4] array at this address:
01003F8 65 66 67 00
and try to pass it to a function defined with a char[4] argument, it will end up passing the address 01003F8.
If I pass the same array in a similar language but using explicit pass-by-reference, it will also pass the address 01003F8.
So, if you were to examine the machine code of such a program which was generated from one of those two languages, could you tell whether it was from the one with true pass-by-reference, or from C which only has pass-by-value?