DMD 1.025 and 2.009 releases

John Reimer terminal.node at gmail.com
Tue Jan 1 20:45:18 PST 2008


Jason House wrote:
> Walter Bright wrote:
> 
>> Jason House wrote:
>>> Has the const/invariant/enum documentation been updated yet?
>>> Looking at http://www.digitalmars.com/d/const3.html, there is no mention
>>> of
>>> enum.  It does discuss manifest constants...
>>>
>>> Can you please update the docs to reflect the new design?
>> See http://www.digitalmars.com/d/enum.html for the enum stuff.
> 
> ... so you're saying that I can define manifest constants in several
> different ways?  Quoting the online docs:
> 
> "The simplest invariant declarations use it as a storage class. It can be
> used to declare manifest constants.
> invariant int x = 3;    // x is set to 3"
> 
> I thought manifest constants were going to be made more explicit.  That way,
> it's known when taking an address of something is valid.  Afterall, the
> docs also say:
> 

Yes, I saw that too.  I'm guessing that Walter was saying here that an 
invariant /also/ can be used as a sort of manifest constant declaration. 
.. not of the formal sort like that of the "anonymous enum"; but people 
might like to take advantage of the invariants immutability for such a 
purpose... and so the same with "const".

I wager these are the 4 ways to do manifests that Walter was referring 
to in earlier posts: invariant, const, named enum, and anonymous enum - 
the last being the "true" manifest constant.  That's why he felt he 
shouldn't have to add another keyword to replace the anonymous enum 
version if he could just stretch enum a bit more at the seams. 
(incidentally, notice that the four ways still exist).

But are these four ways equivalent and the link level?  I don't think 
so. My question is whether this "type" of manifest constant takes up any 
symbol space in the program...you know: the way the libraries used to 
get bloated with D's old constants (something that seemed to 
circumvented with anonymous enums).  Do all these consts (when used like 
manifests) truly mirror the weightless "#define".  I think only the 
"enum" version does...unless the compiler is indeed smart enough here.

But yes, the docs do tend to mix things up a little.  Probably best to 
avoid referring to manifest constants in the discussion on immutables in 
that context.

Other than that, I was surprised that I actually seemed to be able to 
grasp the const/invariant section this time around.  It is fairly 
understandable and simply presented.  Perhaps the complexities and 
problems will show up in actual practice, but for now the explanations 
seemed well done.

-JJR



More information about the Digitalmars-d-announce mailing list