[comp.lang.c++] Will 'const' ever mean constant?

nevin1@ihlpf.ATT.COM (00704a-Liber) (06/11/88)

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.