gpt4 book ai didi

将 C 转换为 Pascal

转载 作者:太空宇宙 更新时间:2023-11-04 07:04:39 25 4
gpt4 key购买 nike

我正在将用 C 编写的代码转换为 Pascal。我在一个看似简单却产生疑惑的地方得到了疑惑!

int Length = ...;  
void *FileBase = ...;
if (Length && FileBase != NULL)
....

上面这行条件“if”,是不是表示“Length”和“Filebase”分别不等于“0”和“Null”?

它与 if (Length <> 0) and (FileBase <> Nil) then 相同 ???

最佳答案

这实际上不是 Delphi 或 Pascal 问题。这是一个关于 C 中运算符优先级的问题。有很多引用资料可以告诉您这方面的信息。例如:http://en.cppreference.com/w/c/language/operator_precedence .

关键是!=的优先级高于&&。所以表达式

Length && FileBase != NULL

同义

Length && (FileBase != NULL)

因为在 C 中,如果值非零则被视为真,在 Delphi/Pascal 中这个表达式将是:

(Length <> 0) and (FileBase <> nil)

关于将 C 转换为 Pascal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34184419/

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