New enum features

Sivo Schilling i-b-p at gmx.net
Mon Jan 7 04:34:33 PST 2008


I have made a small test to investigate the additional enum features
coming with DMD 2.009.

I'm using dmd to compile this test program:

import std.stdio;

// anonymous enum
enum
{
  ival = 1304,
  dval = 1965.0,
  chr1 = 'a',
  chrm = "This is a anonymous enum member string."
}

// manifest constants
enum ival_ = 1304;
enum dval_ = 1965.0;
enum chr1_ = 'b';
enum chrm_ = "This is a manifest constant string.";


void main()
{
  writefln("Test anonymous enum members.");
  writefln("----------------------------");
  writefln("ival = ", ival);
  writefln("dval = ", dval);
  writefln("chr1 = ", chr1);
  writefln("chrm = ", chrm, "\n");

  writefln("Test manifest constants.");
  writefln("------------------------");
  writefln("ival_ = ", ival_);
  writefln("dval_ = ", dval_);
  writefln("chr1_ = ", chr1_);
  writefln("chrm_ = ", chrm_, "\n");

}

and got these results:

Test anonymous enum members.
----------------------------
ival = 1304
dval = 1965
chr1 = a
chrm = This is a anonymous enum member string.

Test manifest constants.
------------------------
ival_ = 1304
dval_ = 1965
chr1_ = b
chrm_ = ¸B        €ÿ Ä… ´3B H­@ 1   ´3B


The last line of output looks wrong, but using a string as an
anonymous enum member gives the desired result.

Is there a difference between an anonymous enum member and a manifest
constant considering a string?

Regards




More information about the Digitalmars-d mailing list