Why does this snippet print the enum identifiers instead of their values?
bearophile
bearophileHUGS at lycos.com
Tue May 28 05:09:27 PDT 2013
Gary Willoughby:
> Why does the following snippet print:
>
> "Started name revision" instead of "Started my-app 1.0a"?
>
> import std.stdio;
>
> enum application : string
> {
> name = "my-app",
> revision = "1.0a",
> }
>
> void main(string[] arguments)
> {
> writefln("Started %s %s", application.name,
> application.revision);
> }
It looks like a compiler bug :-) (Enums of strings are not well
supported. enums were invented mostly for integral types.) If
it's not already in Bugzilla then I suggest to add it there.
By the way, in D enum names as "application" usually start with
an upper case ("Application"), and the name of the main array is
usually "args". Sticking with common practices is better, unless
you have (uncommon) real reasons to do something different.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list