home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / mac / programm / 13153 < prev    next >
Encoding:
Text File  |  1992-07-29  |  1.7 KB  |  43 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!darwin.sura.net!news.udel.edu!bach.udel.edu!lecates
  3. From: lecates@bach.udel.edu (Roy LeCates)
  4. Subject: Think C:  Call by reference?
  5. Message-ID: <Bs5MJ9.AwA@news.udel.edu>
  6. Sender: usenet@news.udel.edu
  7. Nntp-Posting-Host: bach.udel.edu
  8. Organization: University of Delaware
  9. Distribution: na
  10. Date: Wed, 29 Jul 1992 14:21:09 GMT
  11. Lines: 30
  12.  
  13. On the UNIX C++ compilers, there is an option called "call by reference."
  14. It is a very useful way of passing variables to functions.
  15. I would like to know if it exists in Think C.
  16.  
  17. For those who don't know about "call by reference" here's a description:
  18. It performs a function similar to "VAR" variables in Pascal.  That is,
  19. it passes a pointer to the actual variable instead of a copy of the
  20. variable.  This allows the function to modify the actual variable which
  21. was passed, not just a copy.
  22.  
  23. With "call by reference" the compiler automatically handles dereferencing
  24. the pointer, so the programmer only sees the variable -- not the pointer.
  25.  
  26. This is an example of "call by reference" syntax (i.e. the '&' between
  27. the type and variable name):
  28.  
  29. void Do_Something ( int first, int & second );
  30.  
  31. In this example, 'first' would be passed by a COPY of the actual variable.
  32. On the other hand, 'second' would be passed by a POINTER to the actual
  33. variable.  However, since the compiler handles the dereferencing, the
  34. statement "second = first;" is valid in this function.
  35.  
  36. Please e-mail any replies.  Thanks!
  37.  
  38. -- 
  39. ------------------------------------------------------------------
  40. Roy M. LeCates       EE Undergraduate        lecates@bach.udel.edu
  41. University of Delaware Electrical Engineering and Computer Science
  42. ------------------------------------------------------------------
  43.