home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19798 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.1 KB  |  47 lines

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