Const sucks

Nathan Reed nathaniel.reed at gmail.com
Tue Sep 11 10:54:02 PDT 2007


Janice Caron wrote:
> 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.

That places totally unnecessary restrictions on the programmer...there's 
absolutely no reason why you shouldn't be able to take the address of 
something const.

> 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.

It's not /my/ macro idea. :)  (For the record, I don't really like the 
idea of using the macro keyword for this, either.)  Although, as other 
people have pointed out, this doesn't break type safety, just makes the 
type not explicitly stated in the code.

Thanks,
Nathan Reed



More information about the Digitalmars-d mailing list