digitalmars.D.learn - enum values without initializer
- bearophile (8/8) Apr 03 2010 Do you know why this is an error?
- BCS (7/11) Apr 03 2010 The only way to make that legal would be to 1) add a special corner case...
- bearophile (14/17) Apr 03 2010 I see. Then I will think if it's right to remove that "bug" report or no...
- Nick Sabalausky (5/7) Apr 03 2010 Can't you do:
- bearophile (4/10) Apr 04 2010 In my opinion that's a semantic mess, I don't write that. auto is for au...
- Daniel Keep (9/18) Apr 06 2010 No it isn't. 'auto' is a storage class, it has NOTHING to do with type
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/17) Apr 03 2010 I have to ask. :) What does that code supposed to mean?
Do you know why this is an error? struct Foo {} enum Foo f; void main() {} I think there's no need to consider it an error (and it can't cause runtime bugs): http://d.puremagic.com/issues/show_bug.cgi?id=4049 Bye, bearophile
Apr 03 2010
Hello bearophile,Do you know why this is an error? struct Foo {} enum Foo f;The only way to make that legal would be to 1) add a special corner case rule or 2) allow "enum type name;" for all types. -- ... <IXOYE><
Apr 03 2010
BCS :Right, I was not looking for a special case.I see. Then I will think if it's right to remove that "bug" report or not. ----------------I have to ask. :) What does that code supposed to mean? Is Foo the base type of the enum, so that we can create enum values for user types as well?<In D2 Walter has decided to use the keyword "enum" to represent what in D1 is "const". So that's not an enumeration at all, it's just a constant. With other people I think it's a bad choice to use "enum" to say "const", but I think it's one of small warts of D2 that will not change... That code just means that I want to create a compile-time const value initialized at its default (init). But it's not correct current D2 code, you have to write: struct Foo {} enum Foo f = Foo(); void main() {} If you don't want that doplication you can also write: enum auto f = Foo(); Bye, bearophile
Apr 03 2010
"bearophile" <bearophileHUGS lycos.com> wrote in message news:hp8jra$1ln5$1 digitalmars.com...If you don't want that doplication you can also write: enum auto f = Foo();Can't you do: enum f = Foo(); ?
Apr 03 2010
Nick Sabalausky:In my opinion that's a semantic mess, I don't write that. auto is for automatic local type inference and enum is to ask for a compile time constant. Bye, bearophileIf you don't want that doplication you can also write: enum auto f = Foo();Can't you do: enum f = Foo(); ?
Apr 04 2010
bearophile wrote:Nick Sabalausky:No it isn't. 'auto' is a storage class, it has NOTHING to do with type inference. Type inference is triggered when the type is omitted from a declaration. It just turns out that in the majority of cases (variables), the easiest way to do this is to use the default storage class which is used if you don't otherwise specify one: auto. This is why 'const blah = 42;' works: const is used as a storage class and the type is omitted.In my opinion that's a semantic mess, I don't write that. auto is for automatic local type inference and enum is to ask for a compile time constant.If you don't want that doplication you can also write: enum auto f = Foo();Can't you do: enum f = Foo(); ?
Apr 06 2010
bearophile wrote:Do you know why this is an error? struct Foo {} enum Foo f; void main() {} I think there's no need to consider it an error (and it can't cause runtime bugs): http://d.puremagic.com/issues/show_bug.cgi?id=4049 Bye, bearophileI have to ask. :) What does that code supposed to mean? Is Foo the base type of the enum, so that we can create enum values for user types as well? Ali
Apr 03 2010