Manifest constants (was const again)

Bill Baxter dnewsgroup at billbaxter.com
Sat Dec 8 12:19:54 PST 2007


Janice Caron wrote:
> On 12/8/07, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
>> The enum proposal was just to make enum take over for const in declaring
>> manifest constants.  Not to change the behavior of manifest constants.
>>
>> So whatever const s = "hello" does now in D2 should be what it does in
>> the next iteration with enum s = "hello".

FWIW, I ran it with D2 and the const version currently compiles and 
gives you an "invariant(char)*".  But you probably knew that.

> 
> What I'm getting at is, enums have no storage. You can't take the
> address of an enum (wheras you /can/ take the address of
> const-declared things). The impact of that is obvious, for primitive
> types like ints, but string is not a primitive type - it is an
> aggregate; an array.
> 
> So the question I'm asking is, do the actual bytes of the array
> consume runtime storage space? It's not completely obvious to me that
> the answer would be yes.

I see what you mean.  So you're suggesting that if the keyword is going 
to be 'enum' then the behavior *should* perhaps be different from 
current D2 const storage class?

For something with a literal syntax like strings I think the answer 
should be the same as the answer to what you get applying the operation 
to a literal.  So in the above case, "hello".ptr actually gives you an 
invariant(char)* also.  So that seems consistent.



--bb



More information about the Digitalmars-d mailing list