[fpc-devel] Ascending order of enum vals

Martin Frb lazarus at mfriebe.de
Fri Dec 29 20:34:14 CET 2023


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.



More information about the fpc-devel mailing list