Sujet : Re: technology discussion → does the world need a "new" C ?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 12. Jul 2024, 12:38:37
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6r4ju$30oa8$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/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 10.07.2024 17:40, bart wrote:
On 10/07/2024 15:54, Janis Papanagnou wrote:
Values passed (including values of pointers [used for arrays]) are
handled (in the functions) as copies and cannot change the original
entities (values or dereferenced objects) in the calling environment.
>
To make it possible to change entities in the calling environment
in "C" you have to implement the necessary indirection by pointers.
You don't have to do anything at all:
[ snip source code ]
What you've coded is to change an entity that is implicitly passed
to the function through a pointer. (Don't you understand that?)
The indirection is achieved through passing a pointer value, and a
copy of that pointer value is available in the function to address
the data pointed to. That passed pointer is passed by value (which
is the only parameter passing mechanism in "C"). An implicit
indirection does not make the parameter passing magically a "call
by reference" (even if it appears so to the uninformed; like you).
Here it looks superficially as though 'v' is passed by value (and it is
of a size that the ABI /would/ pass by value), yet F changes its
caller's data, perhaps unintentionally.
Any indirection through pointers passed (by "call-by-value"!) to
some function will make it possible change the pointed to original
items in the calling environment. Because the pointer is pointing
to (referring to) the original item does not mean that there's a
"call-by-reference" mechanism; in "C" there is no such mechanism.
Your insistence is amazing.
/I/ am amazed at everyone's insistence that there is nothing remarkable
about this, and that it is nothing at all like pass-by-reference.
Because passing arguments "by reference" is a well established
technical mechanism with the term having a specific meaning. If
you think you can change semantics of that term, or if you will
introduce non-standard phrases like "real call by reference" for
"call by reference" only to misuse the term for your own agenda
that will not only complicate communication; it's plain wrong
and will at best muddy the matter and confuse uninformed readers.
Please be so kind and use the established terms here and don't
misuse them (to fit your own mental universe or whatever).
So, how do I write F in C so that the caller's data is unchanged?
I wonder why you don't know or haven't yet understood that if you
pass pointers that point to any data you can change that original
data through the pointer. You cannot prevent that (i.e. not by
the means we're discussing here).
Sure, true pass-by-reference has some extra properties,
There is no such thing as "true pass-by-reference"; that's called
"pass-by-reference", and it has a well known meaning and semantic.
If you want to (mis-)use that well-defined term for a mechanism
where pointer-values are passed you are just confusing uninformed
readers (and likely anger informed ones).
Janis
[...]