delphi 中的等价运算符
我想知道 Delphi 等价于以下运算符。
++i/--i
i++/i--
i+=1/i-=1
我只知道 i++
的 Inc(i)
和 i--
的 Dec(i)
。
同样根据 Inc(i,1)
表示 i+=1
和 Dec(i,1)
表示 i-= 的概念1.
.
但不知道 --i
和 ++i
。支持吗?
我的假设正确吗?如果没有建议必要的。
提前致谢。
I would like to know Delphi equivalent of the following operators.
++i/--i
i++/i--
i+=1/i-=1
I am aware of just Inc(i)
for i++
and Dec(i)
for i--
.
Also under the notion that Inc(i,1)
for i+=1
and Dec(i,1)
for i-=1
.
But have no idea about --i
and ++i
. Is it supported?
Are my assumptions correct? If not suggest the necessary.
Thanx in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Delphi 没有与这些操作符相当的操作符。
inc
和dec
与 += 和-=
类似,但它们的不同之处在于 C/C++ 版本的计算结果为价值。虽然在 C 和 C++ 中你可以
这样写,但在 Delphi 中使用
inc
是不可能的。因此,在 Delphi 中,我将其写为目睹了看似无穷无尽的关于 i++ + ++i + ++i++ 含义的问题,我很高兴这些运算符在 Delphi 中不存在。
更严重的是,您应该非常谨慎地尝试使用内联函数等来重现此类运算符。一旦开始将这些运算符串在一起形成复杂的表达式,您将观察到不可预测的行为,因为表达式内的函数求值顺序在 Delphi 中未定义。
Delphi has no equivalents to any of those operators.
It is the case that
inc
anddec
are similar to += and-=
but they differ in that the C/C++ versions evaluate to a value.Whilst in C and C++ you can write
this is simply not possible with
inc
in Delphi. So in Delphi I would write it asHaving witnessed a seemingly endless supply of questions about the meaning of
i++ + ++i + ++i++
I for one am happy that these operators do not exist in Delphi.On a more serious note, you should be very wary about trying to reproduce such operators using, for example, inline functions. Once you start stringing such operators together into complex expressions you will observe unpredictable behaviour due to the fact that function evaluation order within expressions is undefined in Delphi.
您可以使用类似这样的内容:
and
并通过各种重载,您可以实现这些 C 运算符的各种变体。
You could use something like this:
and
and with various overloads, you could implement the various variations of these C operators.
惯用的 delphi 风格是将 C++ 事物分离成单独的语句。
如果最里面的最高优先子表达式是预自减,则相当于将其作为 delphi 中命令块中的第一个命令。
C 的表达能力不能也不应该在其他地方复制。不要将您的 C++ 习惯用法带入其他语言并尝试在任何其他语言中使用它们。这就像说英语一样,坚持使用属于粤语的语音规则。没有人会理解你,你将在黑暗中工作。
An idiomatic delphi style would be to separate the C++ things into separate statements.
If the innermost highest precedent subexpression was a pre-decrement then the equivalent is to make that the first command in a block of commands in delphi.
The expressiveness of C cannot and should not be reproduced elsewhere. Do not bring your C++ idioms into other languages and try to use them in any other language ever. It's similar to speaking English, and insisting on using phonetic rules that belong to Cantonese. Nobody will understand you and you'll be working in the dark.