Enums must be ascending. Otherwise a compiler note will be issued... Or not.

Below prog gives
project1.lpr(4,32) Note: Values in enumeration types have to be ascending

But if the values are cast first, then no warning.

The 2nd line will print 255, 0,-2 => which is not ascending.

program Project1;
type

TMyEnum = (e1:=-1,e2:=0, e3:=-2);
//TMyEnum = (e1:=byte(-1),e2:=0, e3:=-2);
//TMyEnum = (e1:=-1,e2:=0, e3:=qword(-2));

var
xa: TMyEnum;


begin
writeln(ord(e1));
writeln(ord(e2));
writeln(ord(e3));
readln;
end.

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to