Hello,
Consider the following code:
program _EnumRange;
type
WideEnum =
(
LoWideEnum = low(int64),
HiWideEnum = high(int64)
);
begin
writeln(' low(int64): ', low(int64));
writeln('high(int64): ', high(int64));
writeln;
writeln(' low(WideEnum): ', ord(low(WideEnum)));
writeln('high(WideEnum): ', ord(high(WideEnum)));
readln;
end.
the low and high of int64 are:
low(int64): -9223372036854775808
high(int64): 9223372036854775807
while the low and high of the enumeration type are:
low(WideEnum): -1
high(WideEnum): 0
Considering that enumerations use a maximum of 4 bytes, it is not a surprise that the range is not what has been declared in the enumeration itself.
What is a bit of a surprise is that the compiler emits no warning, no hint, no nothing about the loss of significant digits in the type.
Also, the resulting range due to bit truncation, while correct, is not exactly intuitive, reinforcing the fact that some sort of warning from the compiler would be very useful in that situation.
Personally, I think the compiler should emit some message informing the programmer that it cannot honor such a type definition.
Comments welcome.