home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!darwin.sura.net!news.udel.edu!bach.udel.edu!lecates
- From: lecates@bach.udel.edu (Roy LeCates)
- Subject: Think C: Call by reference?
- Message-ID: <Bs5MJ9.AwA@news.udel.edu>
- Sender: usenet@news.udel.edu
- Nntp-Posting-Host: bach.udel.edu
- Organization: University of Delaware
- Distribution: na
- Date: Wed, 29 Jul 1992 14:21:09 GMT
- Lines: 30
-
- On the UNIX C++ compilers, there is an option called "call by reference."
- It is a very useful way of passing variables to functions.
- I would like to know if it exists in Think C.
-
- For those who don't know about "call by reference" here's a description:
- It performs a function similar to "VAR" variables in Pascal. That is,
- it passes a pointer to the actual variable instead of a copy of the
- variable. This allows the function to modify the actual variable which
- was passed, not just a copy.
-
- With "call by reference" the compiler automatically handles dereferencing
- the pointer, so the programmer only sees the variable -- not the pointer.
-
- This is an example of "call by reference" syntax (i.e. the '&' between
- the type and variable name):
-
- void Do_Something ( int first, int & second );
-
- In this example, 'first' would be passed by a COPY of the actual variable.
- On the other hand, 'second' would be passed by a POINTER to the actual
- variable. However, since the compiler handles the dereferencing, the
- statement "second = first;" is valid in this function.
-
- Please e-mail any replies. Thanks!
-
- --
- ------------------------------------------------------------------
- Roy M. LeCates EE Undergraduate lecates@bach.udel.edu
- University of Delaware Electrical Engineering and Computer Science
- ------------------------------------------------------------------
-