Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2023-12

Ascending order of enum vals

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

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.

Reply by email