PhobosWatch: manifest => enum

Bruce Adams tortoise_74 at yeah.who.co.uk
Fri Dec 28 14:02:22 PST 2007


On Fri, 28 Dec 2007 21:32:49 -0000, Walter Bright  
<newshound1 at digitalmars.com> wrote:

> Bruce Adams wrote:
>> I can see the desire for manifest constants here. You particularly  
>> don't want to bloat your code
>> with each intermediate value in a compile time computed expression.
>> I've just tried an experiment on gcc (cygming 3.4.4). Compiled objects  
>> are the same size whether
>> enum or static const is used in a factorial template. I see this as  
>> evidence that the enum hack
>> is still just that, a hack to workaround dodgey compilers. So you are  
>> propagating a hack into D
>> if the C++ example is one of your primary reasons.
>
> Doesn't "static const" strike you has a hack? It does to me. It has  
> unique properties that are not deducible from the meaning of static or  
> const by themselves. "const" is also a hack in C++, as "const int"  
> sometimes means "const int" and sometimes just "int".

Not really no. The enum hack is a hack because it is a way of making the  
compiler
do something that was not possible in older versions of the language.  
static const
is not a hack in that sense because it is an endorsed part of the  
C++ standard.
The meaning of static const makes perfect sense from the meanings of  
static and const
in C++. static meaning - belonging to the class (actually the current  
scope)
rather than an instance of the class and const meaning a compile time  
constant.
const can of course mean a read-only view in C++ as well which leads to  
other confusions
and contortions. Personally I find the static meaning "compile time" in D  
a little surprising
and not at all related to any of its C++ meanings.



More information about the Digitalmars-d mailing list