Const sucks

Sean Kelly sean at f4.ca
Mon Sep 10 15:20:45 PDT 2007


Walter Bright wrote:
> Bruce Adams wrote:
>>>> 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";
>> 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).
> 
> windows.h in all its terrifying glory has 10,000 macro declarations. If 
> each one occupied 4 bytes of static data, there's 40K of bloat in every 
> exe.

That sounds about right.  When we converted const values to enum values 
in the Tango Win32 headers, app size dropped by roughly 46k.  But there 
were issues with some of those enum values having the wrong type (-1 set 
to int instead of uint), which led to a few strange bugs.


Sean



More information about the Digitalmars-d mailing list