home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!cs.utexas.edu!torn!utzoo!censor!animal!base!stam.qe.bell.ca!xinxu
- From: xinxu@stam.qe.bell.ca (Xin Xu)
- Subject: Re: Reference vs. Pointer
- Message-ID: <1993Jan22.150917.6815@base>
- Sender: xinxu@mars (Xin Xu)
- Nntp-Posting-Host: mars
- Organization: Telecom Canada E.D.S.
- References: <1993Jan15.175541.247@base> <1993Jan17.171120.193@taumet.com> <1993Jan18.192004.2347@taumet.com>
- Distribution: na
- Date: Fri, 22 Jan 1993 15:09:17 GMT
- Lines: 33
-
- In article <1993Jan18.192004.2347@taumet.com>, steve@taumet.com (Steve Clamage) writes:
- |> steve@taumet.com (Steve Clamage) writes:
- |>
- |> >A reference must be initialized to refer to an existing object at its
- |> >point of definition, and cannot be changed. A reference variable can
- |> >never be null, and you may safely omit testing for null. You never have
- |> >an uninitialized reference, a source of hard-to-find bugs with pointers.
- |>
- |> I had a number of email messages about this, so perhaps some
- |> clarification is in order.
- |>
- |> Null pointers may always be created using completely valid and portable
- |> code, as may uninitialized pointers. Not so for references.
- |>
- |> You can (attempt to) make a null reference, but only by dereferencing
- |> a null pointer or by doing something similar with undefined behavior.
- |> It may "work" on a given implementation, but need not.
- |>
- |> Assuming a reference is not null is as safe as assuming it does not
- |> dangle, and probably safer.
- |> --
- |>
- |> Steve Clamage, TauMetric Corp, steve@taumet.com
-
- Once a reference variable is initialized, the reference binding can not
- be changed. This limits the usage of reference variable.
- What's the meaningful usage of "reference variable" ?
- The only meaningful usage I can see now is to use reference as function
- arguments or function return. I think that allowing function to return
- reference contributes to the capacity of the language. What's the real stuff
- we can do with reference variable if we don't use it as function argument
- or function return ?
- What's the meaningful usage of "reference variable" ?
-