Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
April 03, 2010 enum values without initializer | ||||
---|---|---|---|---|
| ||||
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 |
April 03, 2010 Re: enum values without initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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. #1 is a bad idea as are almost all special case rules #2 is just flat wrong 99.9% of the time. -- ... <IXOYE>< |
April 03, 2010 Re: enum values without initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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,
> bearophile
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?
Ali
|
April 03, 2010 Re: enum values without initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS : > #1 is a bad idea as are almost all special case rules Right, I was not looking for a special case. > #2 is just flat wrong 99.9% of the time. 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 |
April 04, 2010 Re: enum values without initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | "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(); ? |
April 04, 2010 Re: enum values without initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | Nick Sabalausky:
> > If you don't want that doplication you can also write:
> > enum auto f = Foo();
>
> Can't you do:
> enum f = Foo();
> ?
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,
bearophile
|
April 06, 2010 Re: enum values without initializer | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile |
bearophile wrote:
> Nick Sabalausky:
>
>>> If you don't want that doplication you can also write:
>>> enum auto f = Foo();
>> Can't you do:
>> enum f = Foo();
>> ?
>
> 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.
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.
|
Copyright © 1999-2021 by the D Language Foundation