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

Liste des GroupesRevenir à l 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, 01:38:23
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6kl5v$1j8l7$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 10/07/2024 00:50, Keith Thompson wrote:
bart <bc@freeuk.com> writes:
[...]
Arrays can be passed by explicit reference:
>
   void F(int(*A)[20]) {
       printf("%zu\n", sizeof(*A)/sizeof((*A)[0]));    // shows 20
   }
>
That can be called like this:
>
   int a[20];
   F(&a);
 On the language level, that's passing a pointer to an array object.
The pointer itself is passed by value.  Passing a pointer to an array
is conceptually no different than passing a pointer to anything else.
I was replying to:
  "In C, arrays are not passed to functions, period."

C has pass-by-reference in exactly the same way that it has
linked lists.  It has neither as a language feature, but both can
be emulated using pointers.  And you can't really understand how
C handles arrays if you start by asserting that they're "passed
by reference".
This is how I can pass arrays by reference in my language:
    proc F([]int &A) =
        A[2]:=777
    end
    proc main=
        static[]int A = (10,20,30)
        println A[2]            # shows 20
        F(A)
        println A[2]            # shows 777
    end
Without the feature I'd need to use 'ref[]int A' and call as F(&A) (the extra deref inside F is added by the commpiler).
This is how you might do the same thing in C:
   void F(int A[]) {
       A[1]=777;
   }
   int main(void) {
       int A[] = {10,20,30};
       printf("%d\n", A[1]);       // shows 20
       F(A);
       printf("%d\n", A[1]);       // shows 777
   }
To get the 777 output involves somehow passing the array by reference.
But notice how C gives exactly the same result as my code that used by-reference, even though:
  * C "doesn't pass arrays by reference"
  * C's F function uses the same parameter type (only & is missing; maybe
    by-ref is implicit...)
  * No explicit de-ref is needed inside F
  * No explicit address-of is needed when calling F
So C behaves exactly as though it passes arrays by-reference, and yet it doesn't have pass-by-reference. In fact, C does it without even needing to be told!

Date Sujet#  Auteur
9 Jul 24 * Re: technology discussion → does the world need a "new" C ?213David Brown
9 Jul 24 +* Re: technology discussion → does the world need a "new" C ?205bart
9 Jul 24 i+* Re: technology discussion → does the world need a "new" C ?202Ben Bacarisse
9 Jul 24 ii`* Re: technology discussion → does the world need a "new" C ?201bart
9 Jul 24 ii +* Re: technology discussion → does the world need a "new" C ?192Ben Bacarisse
9 Jul 24 ii i+* Re: technology discussion → does the world need a "new" C ?3BGB
10 Jul 24 ii ii`* Re: technology discussion → does the world need a "new" C ?2Ben Bacarisse
10 Jul 24 ii ii `- Re: technology discussion → does the world need a "new" C ?1BGB
9 Jul 24 ii i`* Re: technology discussion → does the world need a "new" C ?188bart
9 Jul 24 ii i +- Re: technology discussion → does the world need a "new" C ?1Tim Rentsch
10 Jul 24 ii i `* Re: technology discussion → does the world need a "new" C ?186Ben Bacarisse
10 Jul 24 ii i  `* Re: technology discussion → does the world need a "new" C ?185bart
10 Jul 24 ii i   `* Re: technology discussion → does the world need a "new" C ?184Ben Bacarisse
10 Jul 24 ii i    +- Re: technology discussion → does the world need a "new" C ?1Thiago Adams
10 Jul 24 ii i    +* Re: technology discussion → does the world need a "new" C ?175bart
10 Jul 24 ii i    i+- Re: technology discussion → does the world need a "new" C ?1Janis Papanagnou
10 Jul 24 ii i    i+* Re: technology discussion → does the world need a "new" C ?54Tim Rentsch
10 Jul 24 ii i    ii+* Re: technology discussion → does the world need a "new" C ?14Michael S
10 Jul 24 ii i    iii+* Re: technology discussion → does the world need a "new" C ?8David Brown
11 Jul 24 ii i    iiii`* Re: technology discussion → does the world need a "new" C ?7Michael S
11 Jul 24 ii i    iiii `* Re: technology discussion → does the world need a "new" C ?6Kaz Kylheku
11 Jul 24 ii i    iiii  `* Re: technology discussion → does the world need a "new" C ?5Michael S
11 Jul 24 ii i    iiii   +- Re: technology discussion → does the world need a "new" C ?1Kaz Kylheku
11 Jul 24 ii i    iiii   +- Re: technology discussion → does the world need a "new" C ?1bart
11 Jul 24 ii i    iiii   +- Re: technology discussion → does the world need a "new" C ?1David Brown
11 Jul 24 ii i    iiii   `- Re: technology discussion → does the world need a "new" C ?1Ben Bacarisse
10 Jul 24 ii i    iii+- Re: technology discussion → does the world need a "new" C ?1Kaz Kylheku
11 Jul 24 ii i    iii`* Re: technology discussion → does the world need a "new" C ?4Tim Rentsch
11 Jul 24 ii i    iii `* Re: technology discussion → does the world need a "new" C ?3BGB
11 Jul 24 ii i    iii  `* Re: technology discussion → does the world need a "new" C ?2Tim Rentsch
11 Jul 24 ii i    iii   `- Re: technology discussion → does the world need a "new" C ?1BGB
10 Jul 24 ii i    ii`* Re: technology discussion → does the world need a "new" C ?39bart
10 Jul 24 ii i    ii +* Re: technology discussion → does the world need a "new" C ?37Michael S
10 Jul 24 ii i    ii i+* Re: technology discussion → does the world need a "new" C ?34bart
11 Jul 24 ii i    ii ii+- Re: technology discussion → does the world need a "new" C ?1Michael S
11 Jul 24 ii i    ii ii`* Re: technology discussion → does the world need a "new" C ?32Tim Rentsch
11 Jul 24 ii i    ii ii `* Re: technology discussion → does the world need a "new" C ?31bart
11 Jul 24 ii i    ii ii  +* Re: technology discussion → does the world need a "new" C ?2Tim Rentsch
11 Jul 24 ii i    ii ii  i`- Re: technology discussion → does the world need a "new" C ?1bart
11 Jul 24 ii i    ii ii  `* Re: technology discussion → does the world need a "new" C ?28Keith Thompson
11 Jul 24 ii i    ii ii   `* Re: technology discussion → does the world need a "new" C ?27bart
11 Jul 24 ii i    ii ii    +* Re: technology discussion → does the world need a "new" C ?25Keith Thompson
11 Jul 24 ii i    ii ii    i+* Re: technology discussion → does the world need a "new" C ?15bart
12 Jul 24 ii i    ii ii    ii`* Re: technology discussion → does the world need a "new" C ?14David Brown
12 Jul 24 ii i    ii ii    ii +* Re: technology discussion → does the world need a "new" C ?12bart
12 Jul 24 ii i    ii ii    ii i+- Re: technology discussion → does the world need a "new" C ?1Janis Papanagnou
12 Jul 24 ii i    ii ii    ii i+* Re: technology discussion → does the world need a "new" C ?7David Brown
12 Jul 24 ii i    ii ii    ii ii`* Re: technology discussion → does the world need a "new" C ?6bart
12 Jul 24 ii i    ii ii    ii ii +* Re: technology discussion → does the world need a "new" C ?2bart
13 Jul 24 ii i    ii ii    ii ii i`- Re: technology discussion → does the world need a "new" C ?1David Brown
13 Jul 24 ii i    ii ii    ii ii `* Re: technology discussion → does the world need a "new" C ?3David Brown
17 Jul 24 ii i    ii ii    ii ii  `* Re: technology discussion → does the world need a "new" C ?2Bart
17 Jul 24 ii i    ii ii    ii ii   `- Re: technology discussion → does the world need a "new" C ?1David Brown
12 Jul 24 ii i    ii ii    ii i`* Re: technology discussion → does the world need a "new" C ?3Keith Thompson
12 Jul 24 ii i    ii ii    ii i `* Re: technology discussion → does the world need a "new" C ?2James Kuyper
12 Jul 24 ii i    ii ii    ii i  `- Re: technology discussion → does the world need a "new" C ?1bart
12 Jul 24 ii i    ii ii    ii `- Re: technology discussion → does the world need a "new" C ?1BGB
11 Jul 24 ii i    ii ii    i`* Re: technology discussion → does the world need a "new" C ?9bart
11 Jul 24 ii i    ii ii    i +- Re: technology discussion → does the world need a "new" C ?1Keith Thompson
12 Jul 24 ii i    ii ii    i +- Re: technology discussion → does the world need a "new" C ?1David Brown
12 Jul 24 ii i    ii ii    i `* Re: technology discussion → does the world need a "new" C ?6Janis Papanagnou
12 Jul 24 ii i    ii ii    i  `* Re: technology discussion → does the world need a "new" C ?5bart
13 Jul 24 ii i    ii ii    i   +* Re: technology discussion → does the world need a "new" C ?3Janis Papanagnou
13 Jul 24 ii i    ii ii    i   i`* Re: technology discussion → does the world need a "new" C ?2Keith Thompson
13 Jul 24 ii i    ii ii    i   i `- Re: technology discussion → does the world need a "new" C ?1Janis Papanagnou
14 Jul 24 ii i    ii ii    i   `- Re: technology discussion → does the world need a "new" C ?1Tim Rentsch
12 Jul 24 ii i    ii ii    `- Re: technology discussion → does the world need a "new" C ?1Thiago Adams
10 Jul 24 ii i    ii i+- Re: technology discussion → does the world need a "new" C ?1Keith Thompson
10 Jul 24 ii i    ii i`- Re: technology discussion → does the world need a "new" C ?1James Kuyper
11 Jul 24 ii i    ii `- Re: technology discussion → does the world need a "new" C ?1Tim Rentsch
10 Jul 24 ii i    i+* Re: technology discussion → does the world need a "new" C ?2James Kuyper
10 Jul 24 ii i    ii`- Re: technology discussion → does the world need a "new" C ?1bart
11 Jul 24 ii i    i`* Re: technology discussion → does the world need a "new" C ?117Ben Bacarisse
11 Jul 24 ii i    i `* Re: technology discussion → does the world need a "new" C ?116bart
11 Jul 24 ii i    i  +* Re: technology discussion → does the world need a "new" C ?2Ben Bacarisse
11 Jul 24 ii i    i  i`- Re: technology discussion → does the world need a "new" C ?1Keith Thompson
11 Jul 24 ii i    i  +* Re: technology discussion → does the world need a "new" C ?112Michael S
11 Jul 24 ii i    i  i`* Re: technology discussion → does the world need a "new" C ?111bart
11 Jul 24 ii i    i  i +- Re: technology discussion → does the world need a "new" C ?1Michael S
11 Jul 24 ii i    i  i `* Re: technology discussion → does the world need a "new" C ?109David Brown
11 Jul 24 ii i    i  i  `* Re: technology discussion → does the world need a "new" C ?108bart
11 Jul 24 ii i    i  i   `* Re: technology discussion → does the world need a "new" C ?107David Brown
11 Jul 24 ii i    i  i    `* Re: technology discussion → does the world need a "new" C ?106bart
11 Jul 24 ii i    i  i     +- Re: technology discussion → does the world need a "new" C ?1Keith Thompson
12 Jul 24 ii i    i  i     +* Re: technology discussion → does the world need a "new" C ?103David Brown
12 Jul 24 ii i    i  i     i`* Re: technology discussion → does the world need a "new" C ?102Janis Papanagnou
12 Jul 24 ii i    i  i     i +* Re: technology discussion → does the world need a "new" C ?29bart
12 Jul 24 ii i    i  i     i i+* Re: technology discussion → does the world need a "new" C ?23Kaz Kylheku
12 Jul 24 ii i    i  i     i ii`* Re: technology discussion → does the world need a "new" C ?22Keith Thompson
25 Aug 24 ii i    i  i     i ii +- Re: technology discussion ? does the world need a "new" C ?1dave thompson 2
2 Sep 24 ii i    i  i     i ii `* Re: technology discussion → does the world need a "new" C ?20Tim Rentsch
2 Sep 24 ii i    i  i     i ii  `* Re: technology discussion → does the world need a "new" C ?19Keith Thompson
2 Sep 24 ii i    i  i     i ii   `* Re: technology discussion → does the world need a "new" C ?18Ben Bacarisse
2 Sep 24 ii i    i  i     i ii    +* Re: technology discussion → does the world need a "new" C ?2Keith Thompson
8 Sep 24 ii i    i  i     i ii    i`- Re: technology discussion → does the world need a "new" C ?1Janis Papanagnou
16 Sep 24 ii i    i  i     i ii    `* Re: technology discussion → does the world need a "new" C ?15Tim Rentsch
16 Sep 24 ii i    i  i     i ii     +* Re: technology discussion → does the world need a "new" C ?13Keith Thompson
16 Sep 24 ii i    i  i     i ii     i+* Re: technology discussion → does the world need a "new" C ?4Janis Papanagnou
17 Sep 24 ii i    i  i     i ii     ii`* Re: technology discussion → does the world need a "new" C ?3Tim Rentsch
17 Sep 24 ii i    i  i     i ii     ii `* Re: technology discussion → does the world need a "new" C ?2Janis Papanagnou
17 Sep 24 ii i    i  i     i ii     ii  `- Re: technology discussion → does the world need a "new" C ?1Tim Rentsch
26 Sep 24 ii i    i  i     i ii     i`* Re: technology discussion → does the world need a "new" C ?8Tim Rentsch
16 Sep 24 ii i    i  i     i ii     `- Re: technology discussion → does the world need a "new" C ?1Ben Bacarisse
12 Jul 24 ii i    i  i     i i+- Re: technology discussion → does the world need a "new" C ?1Janis Papanagnou
12 Jul 24 ii i    i  i     i i`* Re: technology discussion → does the world need a "new" C ?4Keith Thompson
12 Jul 24 ii i    i  i     i +* Re: technology discussion → does the world need a "new" C ?2Kaz Kylheku
12 Jul 24 ii i    i  i     i `* Re: technology discussion → does the world need a "new" C ?70Michael S
12 Jul 24 ii i    i  i     `- Re: technology discussion → does the world need a "new" C ?1James Kuyper
11 Jul 24 ii i    i  `- Re: technology discussion → does the world need a "new" C ?1Tim Rentsch
10 Jul 24 ii i    `* Re: technology discussion → does the world need a "new" C ?7Janis Papanagnou
9 Jul 24 ii `* Re: technology discussion → does the world need a "new" C ?8Kaz Kylheku
9 Jul 24 i+- Re: technology discussion → does the world need a "new" C ?1David Brown
9 Jul 24 i`- Re: technology discussion → does the world need a "new" C ?1Keith Thompson
9 Jul 24 +- Re: technology discussion → does the world need a "new" C ?1Michael S
9 Jul 24 `* Re: technology discussion → does the world need a "new" C ?6BGB

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal