digitalmars.D.learn - static const and user attribute
- Jack Applegame (9/9) May 29 2013 Which difference between enum and static const with initializer?
- Jack Applegame (1/1) May 29 2013 I'm sorry. My english is terrible.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/5) May 29 2013 Please don't say that. :) Your English is very nice and I am sure
- bearophile (5/6) May 29 2013 Currently nearly none. But it will be fixed in two or three DMD
- Dicebot (16/17) May 29 2013 enum is pure compile-time entity. It does not take space or have
- bearophile (5/6) May 29 2013 It will be fixed progressively in the next two or three DMD
- Kenji Hara (3/9) May 29 2013 Please file it in bugzilla.
- bearophile (4/6) May 29 2013 OK, I'll add it a bit later :-)
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
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
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
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
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
On Wednesday, 29 May 2013 at 14:50:36 UTC, bearophile wrote:Dicebot:Please file it in bugzilla. Kenji HaraI think this is a bug.It will be fixed progressively in the next two or three DMD versions. Bye, bearophile
May 29 2013
Kenji Hara:Please file it in bugzilla. Kenji HaraOK, I'll add it a bit later :-) Bye, bearophile
May 29 2013