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 : 09. Jul 2024, 21:28:49
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6k6i0$1h4d3$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
User-Agent : Mozilla Thunderbird
On 09/07/2024 18:22, Ben Bacarisse wrote:
bart <bc@freeuk.com> writes:
 
On 09/07/2024 16:58, Ben Bacarisse wrote:
bart <bc@freeuk.com> writes:
>
Arrays are passed by reference:
>
    void F(int a[20]) {}
>
    int main(void) {
      int x[20];
      F(x);
    }
This is the sort of thing that bad tutors say to students so that they
never learn C properly.  All parameter passing in C is by value.  All of
it.  You just have to know (a) what the syntax means and (b) what values
get passed.
>
The end result is that a parameter declared with value-array syntax is
passed using a reference rather than by value.
>
And it does so because the language says, not because the ABI requires
it. A 2-byte array is also passed by reference.
 An address value is passed by value.  C has only one parameter passing
mechanism.  You can spin it as much as you like, but C's parameter
passing is simple to understand, provided learner tune out voices like
yours.
Little about C's type system is simple. You're doing your students a disservice if you try and hide all the quirks.
There's a discontinuity in the type system when it comes to parameter types (T is is non-array typedef; U is an array typedef):
   Non-Param      Same type as Param
   T a            T a
   T a[10]        T *a
   T a[10][20]    T (*a)[20]
   U a            U *a
   U a[10]        U (*a)[?]         ? is the length of U's array
   U A[10][20]    U (*a)[20][?]
Any top-level array type in a parameter (that is, its description in English starts with 'array of'), is converted to a pointer type (now starts with 'pointer to'). But the lower levels are not affected.
If you were to try the same exercise in one of my languages, if would be a smaller table:
   Param/Non-Param,
   T is array/non-array
   T a
   T a[10]
   T a[10][20]

Sorry, I missed what you wrote.  I don't know why even brought up int
(*)[20] but I thought you were saying that was the type of a.
int(*)[20] would be the type of 'a' inside my function, IF it was properly passed by value instead of some weird combination.
If I define this function in one of my languages, where '&' means pass-by-reference:
   proc f([20]int32 &A)=
   end
and tell it to transpile to C, it produces (minus the name decoration):
   static void f(i32 (*a)[20]) {
   }

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

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal