Const sucks

Janice Caron caron800 at googlemail.com
Tue Sep 11 10:18:38 PDT 2007


On 9/11/07, Nathan Reed <nathaniel.reed at gmail.com> wrote:
> For a regular declaration of a const variable, the
> compiler can optimize away the stored version if it can determine that
> the address is never taken, but this often isn't possible (think of
> class member variables - the compiler can't guarantee that no client
> code will ever take the address).

Then just decree that it be illegal to take the address of a const
class member variable. Problem solved.

What's wrong with:

 class C
 {
     const int X = 42; /* not stored; address may not be taken */
     static int Y = 42; /* consumes memory; address may be taken */
}


I dislike your macro idea, because I want my consts to have a type. I
/like/ type safety, and I want to keep it. I want my constants to be
of the type I declare them to be, not just a piece of text.



More information about the Digitalmars-d mailing list