Path: utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: const Message-ID: <11300@alice.UUCP> Date: 6 Sep 90 18:04:44 GMT References: <10863@cadillac.CAD.MCC.COM> <27503@pasteur.Berkeley.EDU> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 32 In article <27503@pasteur.Berkeley.EDU>, twagner@baobab.berkeley.edu (Tim Wagner) writes: > This points out once again the problems inherent in C's (and therefore C++'s) > use of 'const'. The return type of the function is not a good mechanism > in this case: obviously, one cannot really alter the returned value anyhow, > so calling it 'const' is redundant. However, the context in which that > returned value is used should be controlled; that is, an lvalue getting > such a returned object should be const itself. Not at all! If you assign the result of a function to a variable, the variable gets a copy of that result. Just because the result itself is a constant, that doesn't say anything about the copy. For example: int x = 3; Here, 3 is a `const int,' but that surely does not oblige x to be a const! Similarly: extern const int f(); main() { int x = f(); // ... } Again, there is no particular reason why x should have to be a const. -- --Andrew Koenig ark@europa.att.com