C 代码(带逗号运算符)到 Delphi
C 语言中以下内容的等效 Delphi 代码是什么:
int32 *P;
int32 c0, c1, i, t;
uint8 *X;
t = P[i], c0 = X[t], c1 = X[t + 1];
坦率地说,逗号运算符让我感到困惑。下面的说法是不是大错特错了?
{$POINTERMATH ON}
var P: ^Int32; c0, c1, i, t: Int32; X: ^UInt8;
t:= P[i]; //<--?
c0:= X[t];
c1:= X[t+1];
t:= c1; //<--?
What is the equivalent Delphi code for the following in C:
int32 *P;
int32 c0, c1, i, t;
uint8 *X;
t = P[i], c0 = X[t], c1 = X[t + 1];
Frankly, the comma operator confuses me. Is the following wildly wrong?
{$POINTERMATH ON}
var P: ^Int32; c0, c1, i, t: Int32; X: ^UInt8;
t:= P[i]; //<--?
c0:= X[t];
c1:= X[t+1];
t:= c1; //<--?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C 中的逗号运算符具有最低的优先级。所以你的陈述相当于:
然后从左到右评估。所以它相当于:
但是,如果您做了这样的事情:
那么它将相当于:
因为逗号运算符“返回”其最终操作数。
我还应该指出,因为每个逗号都是一个序列点,所以像这样的东西是明确定义的:
而这不是:
It almost goes without saying: if anyone wrote production C code like your first code snippet, I would have to spank them.
The comma operator in C has the lowest possible precedence. So your statement is equivalent to:
which is then evaluated from left to right. So it's equivalent to:
However, if you had done something like this:
then it would be equivalent to this:
because the comma operator "returns" its final operand.
I should also point out that because each comma is a sequence point, stuff like this is well-defined:
where as this isn't:
It almost goes without saying: if anyone wrote production C code like your first code snippet, I would have to spank them.