home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / std / cplus / 2013 < prev    next >
Encoding:
Text File  |  1993-01-08  |  1.6 KB  |  46 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!stanford.edu!lucid.com!lucid.com!jss
  3. From: jss@lucid.com (Jerry Schwarz)
  4. Subject: Re: Type System
  5. Message-ID: <1993Jan9.001948.28388@lucid.com>
  6. Sender: usenet@lucid.com
  7. Reply-To: jss@lucid.com (Jerry Schwarz)
  8. Organization: Lucid, Inc.
  9. References: <1993Jan1.172044.9659@ucc.su.OZ.AU> <1993Jan4.194318.5340@lucid.com> <C0Iy9o.9x@frumious.uucp>
  10. Date: Sat, 9 Jan 93 00:19:48 GMT
  11. Lines: 33
  12.  
  13. In article <C0Iy9o.9x@frumious.uucp>, pat@frumious.uucp (Patrick Smith) writes:
  14. |> jss@lucid.com (Jerry Schwarz) writes:
  15. |> |The way I understand it, when an object is created (constructed)
  16. |> |it can be "marked" as mutable or immutable. ("Marked" in quotes
  17. |> |because no runtime marking is implied).  This mark cannot be
  18. |> |changed.  The type system is designed so that (barring the
  19. |> |use of unsafe casts) the following rule is assured.
  20. |> |
  21. |> |    If an lvalue has non-const type,
  22. |> |    then it refers to a mutable object.
  23. |> 
  24. |> There is another loophole. :-(
  25. |> But it's (I hope) an unusual type of situation. :-)
  26. |> 
  27. |>    struct A { A(); /*...*/ };
  28. |>    A* pa;
  29. |>    A::A { pa = this; }
  30. |> 
  31. |>    void f() {
  32. |>       const A a;
  33. |>       // Now pa has non-const type but points to an immutable object.
  34. |>    }
  35.  
  36. You're right.  I knew about that loophole, but forgot about it when
  37. I posted my original item.  If anyone has ideas for a clean way
  38. to close this loophole, I'd be interested to hear them.  
  39.  
  40. The problem is that the object is only "marked" immutable when the
  41. constructor returns.  The constructor itself is supposed to be free
  42. to modify the object in any way it chooses.
  43.  
  44.   -- Jerry Schwarz
  45.  
  46.