home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.eiffel
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!spool.mu.edu!umn.edu!csus.edu!netcom.com!nagle
- From: nagle@netcom.com (John Nagle)
- Subject: Re: Semantics of invariants
- Message-ID: <1992Dec18.033811.9746@netcom.com>
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- References: <1992Dec15.213603.16406@bony1.bony.com> <1992Dec16.163847.17559@nrao.edu>
- Date: Fri, 18 Dec 1992 03:38:11 GMT
- Lines: 34
-
- cflatter@nrao.edu (Chris Flatters) writes:
- >If the values of class attributes are not modified outside of the procedures
- >and functions of that class it is sufficient to check the class invariant
- >on exit from each function or procedure since the invarient (sic) will not
- >change between exit from one function/procedure and entry into the next.
-
- This is not quite sufficient, unfortunately. The usefulness of
- class invariants is that one can assume them to be true at entry to
- a procedure exported from a class. Procedures in the class are coded
- assuming the invariant is true (and, strictly, shouldn't assume anything
- about the class variables that isn't expressed in the invariant).
- After manipulating the class variables, the procedure must make the
- invariant true before returning. This is a good, sound way to program.
-
- There's a hole, though. Class reentrancy is a problem. If a
- procedure exported from a class can, directly or indirectly, call
- itself or some other exported procedure on the same object, the
- object can be entered with the invariant in an invalid state.
-
- This comes up in some C++ programs which use "iterators".
- If an iterator iterating over a list calls a function which, say,
- calls the function which
- deletes something from that list, the iterator may dereference a pointer
- to a deleted object.
-
- The implication is that if an object has functions which could
- potentially call something which reenters the object, the invariant must
- be rechecked at object entrance, as well as at exit.
-
- Many invariant checks can be optimized out by a good compiler.
- How well are existing Eiffel compilers doing in this area?
-
- John Nagle
-
-