define should be the keyword for manifest constants
Janice Caron
caron800 at googlemail.com
Thu Dec 13 09:56:07 PST 2007
On 12/13/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> How would the compiler know when compiling a module with a constant whether
> some other module is going to take the address of that constant?
You're thinking old-school. D is new-school. Imports don't just import
symbols, they import abstract symbol trees. Saying "How would the
compiler know when compiling a module with a constant whether some
other module is going to take the address of that constant?" is like
saying "How would the compiler know whether a template needs to be
instantiated?". The point is, it doesn't need to - it just exports the
AST.
In fact, you can mimic #define pi=3.14159 as
template pi { const real pi = 3.14159 }
in one module, and it will take up zero storage space until someone
(possibly in another module) instantiates it with something like
real x = pi!;
Not that I'm suggesting that we use templates for compile-time
constants! (That would be silly). But the fact that we can do it at
all shows that it can be done.
More information about the Digitalmars-d
mailing list