Top 5

Don nospam at nospam.com.au
Tue Oct 14 00:54:43 PDT 2008


Julio César Carrascal Urquijo wrote:
> Hello Benji,
> 
>> I understand the optimization benefits of const values. I'v just never
>> understood what people are talking about with "manifest" constants,
>> and why they deserve to have some special keyword.
>>
>> I take it, from your example code, that you agree with me that there's
>> no need for a "define" or "manifest" keyword...
>>
>> --benji
>>
> 
> Someone correct me if I'm wrong.
> Manifest constants grew out of the necesity of one of the winapi 
> projects. There are lots of constants in the win32 api and they were 
> taking lots of space in the resulting binary. Most projects opted to 
> declare constants using enum because they got replaced by the value at 
> compile time.

It was requested by me. The motivation was a bit different.
Template metaprogramming is slow to compile mainly because of all the 
constants which need to be written into the object files -- they can 
easily be a few megabytes in size. But manifest constants exist only at 
compile time, so they don't need to be written into the obj file. In 
fact, they could rapidly be discarded from the symbol table in most cases.
I observed that in D1.0, it's impossible to take the address of a 
constant, so it was pointless having them in the binary. I proposed that 
they should not be stored in the binary any more, to reduce exe sizes 
and speed compilation.
But Walter said that the behaviour was a bug in DMD.

enum for manifest constants provides the functionality which in D1.0 was 
provided by the bug.



More information about the Digitalmars-d mailing list