Range check error while evaluating constants

1.2k Views Asked by At

I am running into a lots of compiler warnings:

Range check error while evaluating constants

for the similar statements throughout my program.

TxMsg is a byte.

GetRegs(0) returns WORD datatype result.

TxMsg[0] := (GetRegs(0) shr 8) and $0F;

What I found out in my research is that this error is caused by implicit typecasting and that you need to convert int64 type to QWORD. If so, then how do you do that here in my line of code.

UPDATE:

fRegs: Array[0..20] of SmallInt;

TxMsg: Array[0..8] of Byte;

function GetReg(reg:Integer):word;
begin
   if reg <= RegCnt then
      result:=fRegs[reg];
end;
1

There are 1 best solutions below

3
On

You say "byte" and "word" are involved. Both are already unsigned, so I don't know what int64 and qword have to do with it.

To suppress the warning, simply hard-cast the word result of the expression to byte:

TxMsg[0] := byte((GetRegs(0) shr 8) and $0F);