Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!pacbell!att!ihnp4!ihlpf!nevin1 From: nevin1@ihlpf.ATT.COM (00704a-Liber) Newsgroups: comp.lang.c++ Subject: Will 'const' ever mean constant? Message-ID: <5018@ihlpf.ATT.COM> Date: 10 Jun 88 21:56:32 GMT References: <5017@ihlpf.ATT.COM> Reply-To: nevin1@ihlpf.UUCP (Nevin Liber & Darin Adler) Organization: AT&T, Apple Lines: 49 Try running this past your local C++ translator, and look at the code that is emitted: class oops { private: int value; public: oops() { value = 0; } oops operator++() { value = 1; return *this; } }; void ugh() { const oops readonly; readonly++; } You end up with something like this (the names have been changed to protect the humans :-)): struct oops { int value; }; void ugh() { struct oops readonly; readonly.value = 0; readonly = (readonly.value = 1, *(&readonly)); } Notice that a 'const'-declared structure is changing value here! Do we misunderstand something, is this intentional, or is this a bug (misfeature) in C++? Is this something that should go away when the ANSI C standard, and the introduction of 'const' into C, arrives? It's clear that (as has been discussed in this group earlier) function members cannot be declared to take "const className *this" instead of "className *this". It seems that this is more important in light of pathological cases like this, especially for native C++ compilers, since they may implement 'const' directly. ___ A joint posting from: Darin Adler (Apple) ..!sun!apple!darin Nevin Liber (AT&T) ..!ihnp4!ihlpf!nevin1 (send all email here; I will forward) These are our own personal opinions, and (probably) not those of Apple nor AT&T.