home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18965 < prev    next >
Encoding:
Internet Message Format  |  1992-12-29  |  1.9 KB

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