Deutsch English Français Italiano |
<87ikugsta9.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.roellig-ltd.de!news.mb-net.net!open-news-network.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson <Keith.S.Thompson+u@gmail.com> Newsgroups: comp.lang.c Subject: Re: technology discussion =?utf-8?Q?=E2=86=92?= does the world need a "new" C ? Date: Fri, 27 Sep 2024 14:03:58 -0700 Organization: None to speak of Lines: 164 Message-ID: <87ikugsta9.fsf@nosuchdomain.example.com> References: <v66eci$2qeee$1@dont-email.me> <87ikxconq4.fsf@bsb.me.uk> <v6n8iu$24af0$1@dont-email.me> <20240711115418.00001cdf@yahoo.com> <v6oamt$2d8nn$1@dont-email.me> <v6oct4$2djgq$2@dont-email.me> <v6of96$2ekb0$1@dont-email.me> <v6ovfc$2hcpf$1@dont-email.me> <v6p4hf$2icph$1@dont-email.me> <v6qgpu$2t6p7$3@dont-email.me> <v6r33m$30grj$1@dont-email.me> <v6r3iv$30gru$1@dont-email.me> <20240712045301.394@kylheku.com> <87sewesg89.fsf@nosuchdomain.example.com> <865xresvxz.fsf@linuxsc.com> <87h6ay3jaz.fsf@nosuchdomain.example.com> <87mskqtip3.fsf@bsb.me.uk> <8634m0ccjc.fsf@linuxsc.com> <87zfo7rija.fsf@nosuchdomain.example.com> <867cay74m4.fsf@linuxsc.com> <87r095sosv.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Fri, 27 Sep 2024 23:04:04 +0200 (CEST) Injection-Info: dont-email.me; posting-host="1366c00d6f20d908d4f0926f3b327eea"; logging-data="930905"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+KRv2KPezGTpWtRXSJ8ji" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:9Hyc4GEwdRpdboAhJaKPFFBuie8= sha1:7iXYA0K0gmPqDqel82O/bp8Rwnw= Bytes: 8834 Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: > Tim Rentsch <tr.17687@z991.linuxsc.com> writes: [...] >> The "call by" in Algol 60 is used to characterize /parameters/ of >> a function definition. It's important that "call" is used in the >> active voice; parameters are not "called". > > https://dl.acm.org/doi/pdf/10.1145/367236.367262 > > 4.7.5.4. A formal parameter which is called by value cannot in > general correspond to [...] > > Apparently the author of that section did think that parameters (at > least formal parameters) are "called", or did not clearly express what > he actually meant. > > It's a minor point. After some further thought and re-reading of the Algol 60 Report, I no longer think this is a minor point. I had said, and you agreed, that parameters are not "called". I've searched the Algol 60 Report for occurences of "call". It uses that word both to refer to calling procedures *and* to "calling" parameters. And my tentative conclusion is that this whole controversy ("call-by" vs. "pass-by") is simpler than I had thought, and likely than you had thought. The phrase "call by value" made sense when the Algol 60 Report was written, because it was understood at the time that parameters are *called*. It no longer makes as much sense, because that usage of the word "call" has almost entirely died out, and we say that arguments are *passed*. Gory details follow. Some terminology for those who might not be familiar with Algol 60: Algol 60 has "procedures", which may or may not return a value. These correspond to C "functions". Other languages might use terms like "subprogram" or "subroutine". Procedures may have parameters. Procedure calls may include arguments, which are associated with the parameters of the called procedure. C uses the same terminology (but does not have by-name semantics). Some languages refer to parameters and arguments as formal parameters and actual parameters, respectively. What C calls a "function call", Algol 60 calls a "procedure statement". The following is partial list of uses of "call" in the Report. The word "pass" does not appear anywhere in the Report. 4.7.3. Semantics A procedure statement serves to invoke (call for) the execution of a procedure body (cf. section 5.4. Procedure Declarations). 4.7.3.1. Value assignment (call by value) 4.7.3.2. Name replacement (call by name) 4.7.5.1. Strings cannot occur as actual parameters in procedure statements calling procedure declarations having ALGOL 60 statements as their bodies (cf. section 4.7.8). 4.7.5.2. A formal parameter which occurs as a left part variable in an assignment statement within the procedure body and which is not called by value can only correspond to an actual parameter which is a variable (special case of expression]. 4.7.5.3. A formal parameter which is used within the procedure body as an array identifier can only corre- spond to an actual parameter which is an array identifier of an array of the same dimensions. In addition if the formal parameter is called by value the local array created during the call will have the same subscript bounds as the actual array. 4.7.5.4. A formal parameter which is called by value cannot in general [...] 5.4.5. Specifications [...] In this part no formal parameter may occur more than once and formal parameters called by name (cf. section 4.7.3.2) may be omitted altogether. From these examples, it's clear (to me) that the Report uses the word "call" in its modern sense of calling a function -- but it *also* uses the word "call" in reference to formal parameters. Consider this C code: void func(int param1, int param2) { /* ... */ } ... func(10, 20); In C terms, the last line *calls* the function; this includes *passing* the arguments 10 and 20, which results in assigning those values to the parameters param1 and param2. In Algol 60 terms, the last line *calls* the function (procedure); this includes *calling* the formal parameters param1 and param2. If the parameters are called by value, the argument values are copied as in C. If the parameters are called by name, each occurrence of a parameter name in the body of func() is logically replaced by the argument expression. (I'm not sure I've described the semantics entirely correctly.) Consider this C++ code: void func(int by_value, int& by_reference) { /* ... */ } ... int n; func(42, n); In the function call, there are two different argument passing mechanisms, but only one *call*. The call itself is not by value or by reference. The call includes passing two arguments, one by value and one by reference. This is one reason I don't think it makes sense to use "call by" rather than "pass by" for arguments/parameters. (In Algol 60 terms, parameters were "called", so that terminology made sense.) The "call by name" semantics turned out to be more complicated than expected, and as far as I can tell was never adopted by any language other than Algol 60. And in modern usage, the word "call" is used to refer to invoking a function/procedure/subprogram, and is virtually *never* applied to associating an argument to a parameter as part of a function/procedure/subprogram call, other than in the legacy "call by ..." phrasing. That mechanism is almost always referred to as *passing* the argument. In C, function arguments are always passed by value. In C++, arguments may be passed by value or by reference. In some languages, some arguments may be passed by copy-in/copy-out. I've never found the word "pass" to cause any confusion in the latter case. I might say informally that the argument is passed in on the call, and then passed out, back to the caller, when the function returns. My conclusion is that the only reason the term "call by <mechanism>" is used is because of its use in the very influential Algol 60 Report, which was written at a time when the word "call" was applied to parameters. Now that that meaning of "call" has almost completely fallen into disuse, I suggest that "call by <mechanism>" is of historical interest, but "pass by <mechanism>" is much clearer. Still, it's important to recognize the "call by" phrasing, which still appears in the index of K&R2 and the C and C++ standards. I'd still use the phrase "call by name" rather than "pass by name" because it's well known by that phrase. For mechanisms that are still in use in modern languages, I see no point in using the older terminology. I don't know whether the idea of "calling" parameters originated in the Algol 60 report, or whether it was just common usage at the time. Studying the early documentation for languages like Fortran, Cobol, and perhaps PL/I might be illuminating, but I have not (yet) done so. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */