home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sun4nl!and!jos
- From: jos@and.nl (Jos Horsmeier)
- Newsgroups: comp.lang.c
- Subject: Re: Moving from Pascal to C, Help please!!!!!!
- Message-ID: <4269@dozo.and.nl>
- Date: 29 Dec 92 10:05:33 GMT
- References: <78858@hydra.gatech.EDU> <8474@charon.cwi.nl>
- Organization: AND Software BV Rotterdam
- Lines: 37
-
- In article <8474@charon.cwi.nl> dik@cwi.nl (Dik T. Winter) writes:
- |In article <78858@hydra.gatech.EDU> gt6758b@prism.gatech.EDU (Michael Maverick Kopack) writes:
-
- [ Complaints about C: ]
- | > I also HATE that there are no true
- | > pass by reference parameters!
-
- |The second is not a really valid complaint. The difference between call
- |by value and call by reference is specific to Pascal (inherited from Algol
- |60), and in fact artificial. There is no need for such, as C shows with
- |its pointer passing, and as Algol 68 did before by 'ref' passing.
-
- If I remember well, the Algol 60 language had no such thing as `call by
- reference'. This language implemented the `call by name' parameter passing
- mechanism. Though a very subtle difference in many situations, there is
- a difference. Have a look at the following snippet of pseudo code:
-
- a[1]= 1; a[2]= 2; i= 1; f(i, a[i]);
-
- f(x, y) { x= x+1; y= y+1; }
-
- The results for a[1], a[2] and i are as follows:
-
- call by value : a[1]= 1; a[2]= 2; i= 1;
- call by reference: a[1]= 2; a[2]= 2; i= 2;
- call by name : a[1]= 1; a[2]= 3; i= 2;
-
- Also, if I remember well, the original implementors had the _intention_
- to implement the call by reference mechanism, but they simply made a
- mistake by implementing the intended reference as a `thunk' of code:
- a nameless piece of code that re-evaluated the parameter value when
- needed. It was always fun (in a sadistical manner, that is) to see
- people struggle, trying to write a general `swap' routine in Algol 60. ;-)
-
- kind regards,
-
- Jos aka jos@and.nl
-