Delphi Error – W1023 Comparing signed and unsigned types – widened both operands

Delphi Compiler Error

W1023 Comparing signed and unsigned types – widened both operands

Reason for the Error & Solution

To compare signed and unsigned types correctly the compiler must promote both operands to the next larger size data type.

To see why this is necessary, consider two operands, a Shortint with the value -128 and a Byte with the value 130. The Byte type has one more digit of precision than the Shortint type, and thus comparing the two values cannot accurately be performed in only 8 bits. The proper solution for the compiler is to promote both these types to a larger, common, size and then to perform the comparison.

program Produce;
  var
    s : shortint;
    b : byte;

begin
  s := -128;
  b := 130;

  assert(b < s);
end.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...