home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12952 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  2.3 KB

  1. Path: sparky!uunet!munnari.oz.au!goanna!ok
  2. From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Is there a way to flag errors when an automatic array is returned
  5. Message-ID: <14211@goanna.cs.rmit.oz.au>
  6. Date: 27 Aug 92 06:34:57 GMT
  7. References: <3499@babcock.cerc.wvu.wvnet.edu> <1992Aug25.135401.17891@bnr.ca>
  8. Organization: Comp Sci, RMIT, Melbourne, Australia
  9. Lines: 39
  10.  
  11. In article <1992Aug25.135401.17891@bnr.ca>, holiday@bnr.ca (Matthew Holiday) writes:
  12. > In article <KENDALL.92Aug24123852@pen.centerline.com>, kendall@centerline.com (Sam Kendall) writes:
  13. > |> smp@cathedral.cerc.wvu.wvnet.edu (Shailesh M. Potnis) writes:
  14. > |>    Is there a way to flag [returning a pointer to an automatic] as an
  15. > |>    error during compilation.  This is a serious void in C++ which claims
  16. > |>    to remove the pitfalls in C.
  17.  
  18. > |> This pitfall can't be removed without breaking backward compatibility
  19. > |> with C.
  20.  
  21. It didn't work in C either, so it would hardly be a serious loss.
  22.  
  23. > I'm not sure that it would be possible to verify at compile time that a returned
  24. > pointer isn't a pointer to a local variable.
  25.  
  26. At the time, people said that Algol 68 was behind the times.  Maybe it was
  27. ahead of its time.  Yes folks, Algol 68 had the same possible problem, and
  28. forbade it.  If you want to know how to add a reasonable check to a compiler,
  29. read the old how-to-compile-Algol-68 literature.
  30.  
  31. The implementation of Burroughs Algol used to rely on the operating system
  32. detecting "up-level pointer returns", but they made the compiler smarter
  33. around about the II.7 release, I think it was.
  34.  
  35. Basically you do this:
  36.     an L-value is local if it is based on a local automatic value or parameter
  37.     a pointer variable is classified as local if it is ever assigned a local
  38.     pointer
  39.     an R-value is local if it is derived from a local L-value or from
  40.     a pointer variable which might contain a local pointer
  41.     WARN whenever a possibly local pointer value is assigned to a static or
  42.     non-local variable or returned as a result.
  43.  
  44. You can warn about all sorts of likely mistakes "without breaking
  45. backwards compatibility"; a C compiler can warn about anything it pleases
  46. ("%W-CC-BADNAME I don't like variables called "FRED".  Change it.")
  47.  
  48. -- 
  49. You can lie with statistics ... but not to a statistician.
  50.