www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - static const and user attribute

reply "Jack Applegame" <japplegame gmail.com> writes:
Which difference between enum and static const with initializer?

struct A {
      ("enum") enum int c1 = 10;
      ("const") static const int c2 = 20;
}

static assert(__traits(getAttributes, A.c1)[0] == "enum");
static assert(__traits(getAttributes, A.c2)[0] == "const"); // 
error

http://dpaste.dzfl.pl/7887ef90
May 29 2013
next sibling parent reply "Jack Applegame" <japplegame gmail.com> writes:
I'm sorry. My english is terrible.
May 29 2013
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 05/29/2013 06:32 AM, Jack Applegame wrote:

 I'm sorry. My english is terrible.
Please don't say that. :) Your English is very nice and I am sure everybody here appreciates that you write in English. Ali
May 29 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Jack Applegame:

 Which difference between enum and static const with initializer?
Currently nearly none. But it will be fixed in two or three DMD versions, and they will become const and enum. Bye, bearophile
May 29 2013
prev sibling parent reply "Dicebot" <m.strashun gmail.com> writes:
On Wednesday, 29 May 2013 at 13:30:12 UTC, Jack Applegame wrote:
 Which difference between enum and static const with initializer?
enum is pure compile-time entity. It does not take space or have a location, it is just a named value. "static const x = 42" is a thread-local variable which is initialized to 42 and won't change. You still can take its address and do anything you can do with normal const variable. Well, that is how it is supposed to be. In practice, looks like DMD does some weird optimization for const value types. Global module scope, 2.063: (42) int x1 = 42; (42) const int x2 = 42; (42) const int x3; pragma(msg, __traits(getAttributes, x1)); // works pragma(msg, __traits(getAttributes, x2)); // fails pragma(msg, __traits(getAttributes, x3)); // works I think this is a bug.
May 29 2013
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Dicebot:

 I think this is a bug.
It will be fixed progressively in the next two or three DMD versions. Bye, bearophile
May 29 2013
parent reply "Kenji Hara" <k.hara.pg gmail.com> writes:
On Wednesday, 29 May 2013 at 14:50:36 UTC, bearophile wrote:
 Dicebot:

 I think this is a bug.
It will be fixed progressively in the next two or three DMD versions. Bye, bearophile
Please file it in bugzilla. Kenji Hara
May 29 2013
parent "bearophile" <bearophileHUGS lycos.com> writes:
Kenji Hara:

 Please file it in bugzilla.

 Kenji Hara
OK, I'll add it a bit later :-) Bye, bearophile
May 29 2013