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