www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Strange enum .min, .init and .max

reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Using DMD 0.121, Windows 98SE.

----------
import std.stdio;

enum ABC {
     A = 3, B, C, D = 10, E = -5, F, G = 20, H = 15
}

void main() {
     ABC value;
     writefln("%d %d %d %d", cast(int) ABC.min, cast(int) ABC.init,
       cast(int) ABC.max, cast(int) value);
}
----------
3 0 -4 3
----------

It seems to be treating enum types as unsigned when calculating the 
range.  Specifying an enum base type of either byte, short, int or long 
makes no difference.

Notice also that the .init property seems to bear no relation to what an 
ABC really is initialised to.

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.
Apr 29 2005
parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stewart Gordon schrieb am Fri, 29 Apr 2005 09:25:34 +0100:
 Using DMD 0.121, Windows 98SE.

 ----------
 import std.stdio;

 enum ABC {
      A = 3, B, C, D = 10, E = -5, F, G = 20, H = 15
 }

 void main() {
      ABC value;
      writefln("%d %d %d %d", cast(int) ABC.min, cast(int) ABC.init,
        cast(int) ABC.max, cast(int) value);
 }
 ----------
 3 0 -4 3
 ----------

 It seems to be treating enum types as unsigned when calculating the 
 range.  Specifying an enum base type of either byte, short, int or long 
 makes no difference.

 Notice also that the .init property seems to bear no relation to what an 
 ABC really is initialised to.

Enum.min/max are known: http://dstress.kuehne.cn/run/enum_14.d http://dstress.kuehne.cn/run/enum_15.d http://dstress.kuehne.cn/run/enum_16.d Added to DStress as http://dstress.kuehne.cn/run/enum_17_A.d http://dstress.kuehne.cn/run/enum_17_B.d http://dstress.kuehne.cn/run/enum_18_A.d http://dstress.kuehne.cn/run/enum_18_B.d http://dstress.kuehne.cn/run/enum_19_A.d http://dstress.kuehne.cn/run/enum_19_B.d http://dstress.kuehne.cn/run/enum_20_A.d http://dstress.kuehne.cn/run/enum_20_B.d http://dstress.kuehne.cn/run/enum_21_A.d http://dstress.kuehne.cn/run/enum_21_B.d http://dstress.kuehne.cn/run/enum_22.d http://dstress.kuehne.cn/run/enum_23.d http://dstress.kuehne.cn/run/enum_24.d http://dstress.kuehne.cn/run/enum_25.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCd9Lf3w+/yD4P9tIRAvQkAJ0cFfZoGDwiuzSHzFGY0aSsdloi+wCgruJl AQTEzNneTJXPgod9hxW9d+o= =8kg+ -----END PGP SIGNATURE-----
May 03 2005