Fritzew 51 Posted July 30, 2019 (edited) Delphi 10.3.2 This code will not compile! Stripped down from a TestSuite for our codebase. Can't believe it. program Project17; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; Procedure Test; var int32max: Int64; begin int32max := MaxInt + 1; //Error here writeLn(Format('Integer %20d', [int32max])); writeLn(Format('Integer %20u', [-int32max])); end; begin try Test; readln; except on E: Exception do writeLn(E.ClassName, ': ', E.Message); end; end. Error (in German) [dcc32 Fehler] Project17.dpr(13): E2099 Überlauf bei Konvertierung oder arithmetischer Operation Edited July 30, 2019 by Fritzew Share this post Link to post
Dalija Prasnikar 1396 Posted July 30, 2019 Working as designed. Compiler evaluates mathematical operation first and only then it will do assignment. Since your operation works on two integers, the result will also be integer - and it will overflow at compile time. You need to typecast at least one of the operators to Int64 to widen operation result. 4 Share this post Link to post
Fritzew 51 Posted July 30, 2019 You are right and I I need a break for sure..... int32max := Int64(MaxInt) + 1; // will work Shame on me Share this post Link to post