Thread overview
enum is int or uint?
Nov 03, 2004
shinichiro.h
Nov 11, 2004
Lionello Lunesu
Nov 12, 2004
shinichiro.h
Nov 14, 2004
Thomas Kühne
November 03, 2004
Hi,

When I compile the following code with DMD, it does not fail. But with GDC, it fails:

int main() {
    enum E { A, B };
    E e = -E.B;
    assert(e < 0);
    return 0;
}

That's because DMD treats enum as int but GDC may treat as uint. The language specification of D says the behavior of DMD is correct.

  The EnumBaseType is the underlying type of the enum. It must be an integral
  type. If omitted, it defaults to int.

http://digitalmars.com/d/enum.html

------------------
 shinichiro.h
November 11, 2004
Seems strange to me that you're allowed to do "operator -" on an enum at
all.
The result is not a valid value for enum E.

Lio.


November 12, 2004
> Seems strange to me that you're allowed to do "operator -" on an enum at
> all.
> The result is not a valid value for enum E.

I think enum of C and D is just one of the integral type and IMHO my code is legal. But there is not the essence of the problem. So I refined my code.

int main() {
    enum E { A = -1 };
    E e = E.A;
    assert(e < 0);
    return 0;
}
November 14, 2004
added to DStress as:

http://svn.kuehne.cn/dstress/run/enum_09.d

shinichiro.h schrieb am Freitag, 12. November 2004 15:32:
> So I refined my code.
> 
> int main() {
>     enum E { A = -1 };
>     E e = E.A;
>     assert(e < 0);
>     return 0;
> }