Manifest constants (was const again)
Bruce Adams
tortoise_74 at yeah.who.co.uk
Sat Dec 8 14:37:29 PST 2007
On Sat, 08 Dec 2007 19:44:50 -0000, Janice Caron <caron800 at googlemail.com>
wrote:
> On 12/8/07, Walter Bright <newshound1 at digitalmars.com> wrote:
>> No, that would be:
>>
>> enum defname = "upload.log";
>> enum float fudge = 61.74;
>> enum char starter = 'r';
>> enum qwerty = 0xF4;
>> enum foobar = SomeFunc("foobar");
>
> The first one is interesting. Can I do
>
> enum s = "hello";
> auto p = s.ptr;
>
> ?
You're just evil aren't you? If its a manifest constant you can't take its
address
without making it manifest beyond the compiler. That means the .ptr
property is not useable.
I think that should be a compile time error.
I don't really understand the problem myself.
I always thought it was common sense that a 'simple' constant should only
take
up space:
1) If it is used
1a) if it is never used it should use no space
1b) if it is used only a few times its the compilers decision whether to
place it in .bss
2) If you need to take the address of it
I had assumed this was the case in D.
I guess the problem is to do with modules. You don't know at compile time
whether it will
be used. So I guess you do need a way to say don't use any space after all.
More information about the Digitalmars-d
mailing list