www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - TDPL enum greet = "Hello";

reply Paolo Invernizzi <arathorn fastwebnet.it> writes:
Hi all,
On page 273 of TDPL, we have:

enum euler = 2.78;
euler = 2.73 // Error! Cannot modify enum value!

But with D 2.047 I can do:

enum greet = "Hello";
greet = "Ciao"; // Ok?

So the question is, enumerated values are constant?
Cheers, Paolo
Aug 08 2010
parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Paolo Invernizzi <arathorn fastwebnet.it> wrote:

 Hi all,
 On page 273 of TDPL, we have:

 enum euler = 2.78;
 euler = 2.73 // Error! Cannot modify enum value!

 But with D 2.047 I can do:

 enum greet = "Hello";
 greet = "Ciao"; // Ok?

 So the question is, enumerated values are constant?

There is a bug in DMD in which string literals are lvalues[1]. That is the problem you here have run into. [1]: http://d.puremagic.com/issues/show_bug.cgi?id=4539 -- Simen
Aug 08 2010