HomeDelphiDelphi Error – W1024 Combining signed and unsigned types – widened both operands

Delphi Error – W1024 Combining signed and unsigned types – widened both operands

Delphi Compiler Error

W1024 Combining signed and unsigned types – widened both operands

Reason for the Error & Solution

To mathematically combine signed and unsigned types correctly the compiler must promote both operands to the next larger size data type and then perform the combination.

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

The compiler will only produce this warning when the size is extended beyond what would normally be used for calculating the result.

{$APPTYPE CONSOLE}
program Produce;
  var
    i : Integer;
    c : Cardinal;

begin
  i := -128;
  c := 130;
  Writeln(i + c);
end.


In the example above, the compiler warns that the expression will be calculated at 64 bits rather than the supposed 32 bits.

Share:

Leave A Reply

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

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...