| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
November 03, 2004 enum is int or uint? | ||||
|---|---|---|---|---|
| ||||
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 Re: enum is int or uint? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to shinichiro.h | 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 Re: enum is int or uint? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | > 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 Re: enum is int or uint? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to shinichiro.h | 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; > } | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply