【发布时间】:2011-11-24 02:08:42
【问题描述】:
在 Delphi 中编写 no-op statement 的最佳方法是什么?
获取此代码:
if a=b then
SomeOldStatement
else
AnotherStatement;
并说你暂时想退出SomeOldStatement。
你会选择这个解决方案吗:
if a=b then
//SomeOldStatement
else
AnotherStatement;
就我个人而言,我不喜欢空的 then 部分,并希望在其中有 一些东西可编译...
if a=b then
NoOp
//SomeOldStatement
else
AnotherStatement;
【问题讨论】:
-
你试过
asm nop end;吗? -
@RRUZ:没试过,但我想到了这个替代方案。我想它工作正常,但它与内联 asm 非法的 64 位不兼容。
-
procedure Noop; asm nop end;可以。我想这是最好的解决方案。您应该添加您的建议作为答案:-) -
我更喜欢“//DoNothing”而不是“//SomeOldStatement”。在这种情况下,您也可以使用 Assert(a=b)。
-
@JørnE.Angeltveit,但是如果你将
nop指令放在一个名为Noop的过程中,你将添加一个JMP 和RET 指令,这与直接添加的实际效果不同nop指令。在这种情况下不是更好只有一个空程序procedure Noop; begin end;?
标签: delphi coding-style noop