Const sucks

Bruce Adams tortoise_74 at yeah.nospam.mehoo.co.uk
Mon Sep 10 14:47:17 PDT 2007


Carlos Santander Wrote:

> Walter Bright escribió:
> > Const, final, invariant, head const, tail const, it's grown into a 
> > monster. It tries to cover all the bases, but in doing so is simply not 
> > understandable.
> > 
[snip]
> 
> > o  So, we still need a method to declare a constant that will not 
> > consume memory. We'll co-opt the future macro syntax for that:
> > 
> >     macro x = 3;
> >     macro s = "hello";
> 
> Am I the only one who doesn't like this syntax? I guess it kinda makes sense, 
> but I just don't like how it looks.
> 
> -- 
> Carlos Santander Bernal

I'm not clear why this is even needed.
Surely "static const" implies some level of don't consume any memory by virtue of meaning "available at compile time". 
If you need more than that, rather than trusting the compiler then I second "inline" rather than macro, but honestly I can't think of an example where this will give you a worthwhile performance gain (unlike an inline function).

Regards,
         Bruce.



More information about the Digitalmars-d mailing list