home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!leland!interran
- From: interran@uluru.Stanford.EDU (John Interrante)
- Subject: Re: Pointer or Reference Arguments
- In-Reply-To: rmartin@thor.Rational.COM's message of 7 Sep 92 13:06:25 GMT
- Message-ID: <INTERRAN.92Sep7225351@uluru.Stanford.EDU>
- Sender: news@leland.Stanford.EDU (Mr News)
- Organization: Stanford University
- References: <1992Sep7.075249.22855@news.uni-stuttgart.de> <rmartin.715871185@thor>
- Date: 7 Sep 92 22:53:51
- Lines: 24
-
- In article <rmartin.715871185@thor>, rmartin@thor.Rational.COM (Bob Martin) writes:
- > |1) Reference arguments are used only when aliasing
- > |occurs and the parameter is used only during the
- > |lifetime of the function. Pointers are used whenever the
- > |function might keep a copy of the pointer for later use,
- > |e.g., store it in a private list.
-
- > |2) Reference arguments are used whenever you must supply
- > |a valid object to the function. Pointers are used when 0
- > |might be a valid parameter as well.
-
- > My objection to style 1) is that it must compete with zero pointers.
- > i.e. an argument which qualifies as a reference under fule 1) might
- > still have to be a pointer if it can be zero...
-
- What do you do if you have to keep around a pointer to the object for
- later use *and* the caller must always supply a valid object? If you
- use a reference parameter, then you have to take the address of the
- reference inside your function. That opens the door for havoc if the
- caller unsuspectingly passes a stack-allocated object. If you use a
- pointer parameter in such cases, then I have no objection.
- --
- John Interrante / interran@uluru.stanford.edu
- Computer Systems Laboratory, Stanford University
-