Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing "combining signed and unsigned types widened both operands" compiler warning

This code, which is used to setup a component, produces a compiler warning:

[DCC Warning] Unit1.pas(742): W1024 Combining signed and unsigned types 
                            - widened both operands
var
  iPrecision: cardinal;
  iRadius: cardinal;
  iActive: boolean;
  iInProximity: boolean;

iPrecision := Max(50, 100 - (3 + 2 * ord(iActive and iInProximity)) * iRadius);

Can this be typecast somehow to prevent a compiler warning?

like image 629
Bill Avatar asked Dec 16 '22 09:12

Bill


1 Answers

In your case, ord() returns an integer, so needs to be explicitely type-casted to cardinal, by changing ord() into cardinal() as such:

iPrecision := Max(50, 100 - (3 + 2 * cardinal(iActive and iInProximity)) * iRadius);

You will get rid of the warning, and your code will be almost the same.

like image 196
Arnaud Bouchez Avatar answered Dec 17 '22 22:12

Arnaud Bouchez