Re: technology discussion → does the world need a "new" C ?

Liste des GroupesRevenir à cl c 
Sujet : Re: technology discussion → does the world need a "new" C ?
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.c
Date : 10. Jul 2024, 16:40:29
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6ma1d$1vfv2$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
User-Agent : Mozilla Thunderbird
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:
   #include <stdio.h>
   typedef unsigned char byte;
   typedef byte vector[4];
   void F(vector a) {
       a[0]+=3;
       a[1]+=3;
   }
   int main(void) {
       vector v = {10,20,30,40};
       printf("%d %d %d %d\n", v[0], v[1], v[2], v[3]);  // 10 20 30 40
       F(v);
       printf("%d %d %d %d\n", v[0], v[1], v[2], v[3]);  // 13 23 30 49
   }
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.

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.
So, how do I write F in C so that the caller's data is unchanged?
Sure, true pass-by-reference has some extra properties, but if I wanted to duplicate the behaviour of the above in my language, I have to use pass-by-reference.
In C you get that behaviour anyway (possibly to the surprise of many), in a language which only has pass-by-value, and without needing explicit pointers.
That really is remarkable. And not unsafe at all!

Date Sujet#  Auteur
5 Jul 24 * Re: technology discussion → does the world need a "new" C ?306Lawrence D'Oliveiro
5 Jul 24 `* Re: technology discussion → does the world need a "new" C ?305BGB
5 Jul 24  +* Re: technology discussion → does the world need a "new" C ?2Lawrence D'Oliveiro
5 Jul 24  i`- Re: technology discussion → does the world need a "new" C ?1yeti
5 Jul 24  +* Re: technology discussion → does the world need a "new" C ?275Keith Thompson
5 Jul 24  i+- Re: technology discussion → does the world need a "new" C ?1Lawrence D'Oliveiro
14 Jul 25  i`- 
5 Jul 24  +* Re: technology discussion → does the world need a "new" C ?26bart
5 Jul 24  i+- Re: technology discussion → does the world need a "new" C ?1BGB
6 Jul 24  i`* Re: technology discussion → does the world need a "new" C ?24Lawrence D'Oliveiro
6 Jul 24  i +* Re: technology discussion → does the world need a "new" C ?17Keith Thompson
6 Jul 24  i i+- Re: technology discussion → does the world need a "new" C ?1Janis Papanagnou
6 Jul 24  i i`* Re: technology discussion → does the world need a "new" C ?15Lawrence D'Oliveiro
6 Jul 24  i i +- Re: technology discussion → does the world need a "new" C ?1Ben Bacarisse
6 Jul 24  i i +- Re: technology discussion → does the world need a "new" C ?1Keith Thompson
7 Jul 24  i i +* Re: technology discussion → does the world need a "new" C ?10James Kuyper
10 Jul 24  i i i`* Re: technology discussion → does the world need a "new" C ?9Lawrence D'Oliveiro
10 Jul 24  i i i `* Re: technology discussion → does the world need a "new" C ?8James Kuyper
11 Jul 24  i i i  `* Re: technology discussion → does the world need a "new" C ?7Lawrence D'Oliveiro
11 Jul 24  i i i   +* Re: technology discussion → does the world need a "new" C ?2David Brown
11 Jul 24  i i i   i`- Re: technology discussion → does the world need a "new" C ?1Malcolm McLean
11 Jul 24  i i i   +* Re: technology discussion → does the world need a "new" C ?3bart
11 Jul 24  i i i   i`* Re: technology discussion → does the world need a "new" C ?2Chris M. Thomasson
12 Jul 24  i i i   i `- Re: technology discussion → does the world need a "new" C ?1Chris M. Thomasson
11 Jul 24  i i i   `- Re: technology discussion → does the world need a "new" C ?1James Kuyper
7 Jul 24  i i +- Re: technology discussion → does the world need a "new" C ?1Tim Rentsch
25 Aug 24  i i `- Re: technology discussion ? does the world need a "new" C ?1dave thompson 2
6 Jul 24  i +- Re: technology discussion → does the world need a "new" C ?1Janis Papanagnou
6 Jul 24  i +- Re: technology discussion → does the world need a "new" C ?1James Kuyper
6 Jul 24  i `* Re: technology discussion → does the world need a "new" C ?4bart
7 Jul 24  i  `* Re: technology discussion → does the world need a "new" C ?3Keith Thompson
7 Jul 24  i   `* Re: technology discussion → does the world need a "new" C ?2bart
7 Jul 24  i    `- Re: technology discussion → does the world need a "new" C ?1Keith Thompson
5 Jul 24  `- Re: technology discussion → does the world need a "new" C ?1lexi hale

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal