Private enum members + Descent

Yigal Chripun yigal100 at gmail.com
Tue Oct 27 06:32:58 PDT 2009


Lars T. Kyllingstad Wrote:

> 
> I was going to protest: "But what about const struct members? Should the 
> size of the following struct depend on whether the compiler determines 
> it can optimize by turning its const member into a manifest constant?"
> 
>    struct Foo { const int bar = 123; }
> 
> But then I decided to actually try it with the current DMD2, and found 
> that the compiler does just that!
> 
>    writeln(Foo.sizeof);    // Prints "1", not "4"
> 
>    Foo foo;
>    auto p = &foo.bar;   // Error: constant 123 is not an lvalue
> 
> What's going on? Is this intended behaviour?
> 
> -Lars

what D version? 
in D1 const is a manifest constant as far as I know. 
to answer to general question, "what about structs": 
I'd say that the same rules should apply just like inside functions. 

struct Foo { const int num = 42; } // num should be a manifest const

can you give a use-case/example where you wouldn't want to do that but rather store the constant in the struct? 




More information about the Digitalmars-d mailing list