www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: const again

reply guslay <guslay gmail.com> writes:
Walter Bright Wrote:
 
 Yes for that reason, and the other reason is one rarely wants storage 
 allocated for manifest constants. windows.d has 10,000 declarations in 
 it, who wants 40K of executable bloat from const declarations?
 

const int x = 1; Doesn't x get substituted by 1 everywhere in a constant propagation pass? I thought it didn't take storage, at least in optimization mode.
Dec 06 2007
parent reply "Kris" <foo bar.com> writes:
"guslay" <guslay gmail.com> wrote in message 
news:fjao2r$ii4$1 digitalmars.com...
 Walter Bright Wrote:
 Yes for that reason, and the other reason is one rarely wants storage
 allocated for manifest constants. windows.d has 10,000 declarations in
 it, who wants 40K of executable bloat from const declarations?

const int x = 1; Doesn't x get substituted by 1 everywhere in a constant propagation pass? I thought it didn't take storage, at least in optimization mode.

all those Win32 constants actually adds over 50KB of bloat. Tango would up using enum instead, and pulled some silly linker stunts to eliminate the bloat. I think you can take the address of a const?
Dec 06 2007
next sibling parent guslay <guslay gmail.com> writes:
Kris Wrote:

 "guslay" <guslay gmail.com> wrote in message 
 news:fjao2r$ii4$1 digitalmars.com...
 Walter Bright Wrote:
 Yes for that reason, and the other reason is one rarely wants storage
 allocated for manifest constants. windows.d has 10,000 declarations in
 it, who wants 40K of executable bloat from const declarations?

const int x = 1; Doesn't x get substituted by 1 everywhere in a constant propagation pass? I thought it didn't take storage, at least in optimization mode.

all those Win32 constants actually adds over 50KB of bloat. Tango would up using enum instead, and pulled some silly linker stunts to eliminate the bloat. I think you can take the address of a const?

You're right, without whole program optimization it would probably only be optimized within the scope of a module.
Dec 06 2007
prev sibling next sibling parent Don Clugston <dac nospam.com.au> writes:
Kris wrote:
 "guslay" <guslay gmail.com> wrote in message 
 news:fjao2r$ii4$1 digitalmars.com...
 Walter Bright Wrote:
 Yes for that reason, and the other reason is one rarely wants storage
 allocated for manifest constants. windows.d has 10,000 declarations in
 it, who wants 40K of executable bloat from const declarations?

Doesn't x get substituted by 1 everywhere in a constant propagation pass? I thought it didn't take storage, at least in optimization mode.

all those Win32 constants actually adds over 50KB of bloat. Tango would up using enum instead, and pulled some silly linker stunts to eliminate the bloat. I think you can take the address of a const?

No, you can't, but IIRC Walter said that was actually a bug. Currently they create bloat, but are inaccessable!
Dec 07 2007
prev sibling parent Walter Bright <newshound1 digitalmars.com> writes:
Kris wrote:
 I think you can take the address of a const?

Yes, which is one of the problems with using const to declare manifest constants. The other is the type of the constant will be 'const', which may not be desirable.
Dec 08 2007