gpt4 book ai didi

delphi - 防止 "combining signed and unsigned types widened both operands"编译器警告

转载 作者:行者123 更新时间:2023-12-03 15:18:24 26 4
gpt4 key购买 nike

此代码用于设置组件,会产生编译器警告:

[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);

是否可以通过某种方式进行类型转换以防止编译器警告?

最佳答案

在您的情况下,ord()返回一个整数,因此需要通过更改显式类型转换为cardinal >ord()cardinal() 中,如下所示:

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

您将摆脱警告,并且您的代码将几乎相同。

关于delphi - 防止 "combining signed and unsigned types widened both operands"编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17266462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com