[英]warning: left-hand operand of comma expression has no effect
i see this warning How to do fix it? 我看到这个警告怎么办呢?
Temp += (Table[i, temp3] - (MSB[i] ^ 0x1));
warning: left-hand operand of comma expression has no effect 警告:逗号表达式的左侧操作数无效
what is Table object? 什么是Table对象? If it is 2-dimensional array then you should write
如果它是二维数组,那么你应该写
Table[i][temp3]
In your code 在你的代码中
[i, temp3]
is a comma operator - it evaluates the 1st parameter (i), ignores it and returns temp3, so you can just drop i if Table is some kind of container that accepts single-index to access its objects 是一个逗号运算符 - 它计算第一个参数(i),忽略它并返回temp3,所以如果Table是某种接受单索引访问其对象的容器,你可以放弃i
The comma operator evaluates any number of expressions from left to right, and results in the value of the right-most one. 逗号运算符从左到右计算任意数量的表达式,并产生最右边的表达式的值。
You have a comma in Table[i, temp3]
, which is exactly as doing Table[temp3]
. 你有一个逗号
Table[i, temp3]
这也正是因为这样做Table[temp3]
Were you trying to do Table[i][temp3]
to access a position in a bidimensional array? 您是否尝试使用
Table[i][temp3]
来访问二维数组中的位置?
edit : I'll explain some more, it may be useful for you. 编辑 :我会再解释一下,它可能对你有用。 I won't be 100% precise, it's just to give you an idea of what's going on.
我不会100%精确,它只是让你知道发生了什么。
Why do you have to use two pairs of brackets to access a "cell" in your "table"? 为什么必须使用两对括号来访问“表格”中的“单元格”? With one-dimensional arrays,
array[i]
will land you on the i-th element of the array, right? 使用一维数组,
array[i]
会让你进入数组的第i个元素,对吗? Well, with a two-dimensional array, let's call it table as you did, table[i]
will land you on the i-th element as well. 好吧,使用二维数组,让我们像你一样调用它表,
table[i]
也将你降落在第i个元素上。 This time, though, that element is another array: the whole i-th row of the table. 但是这一次,该元素是另一个数组:表的第i行。
So if table[i]
is a row of the table, which is just another array, how do you access column j? 因此,如果
table[i]
是table[i]
的一行,这只是另一个数组,那么如何访问列j? Well, you have to go to row[j]
, which is table[i][j]
. 好吧,你必须去
row[j]
,这是table[i][j]
。
Multidimensional arrays in C are "arrays of arrays". C中的多维数组是“数组数组”。
错误的语法 - 如果Table
是一个二维数组,请使用Table[i][temp3]
。
What do you mean by i, temp3
? 你是什么意思
i, temp3
? If Table
is a 2D array, access element (i,temp3) with Table[i][temp3]
. 如果
Table
是2D数组,则使用Table[i][temp3]
访问元素(i,temp3)。
Edit: Since I was slow enough to be beat by several answers, I'll add something so that my answer isn't just a duplicate of earlier ones: What does i, temp3
really mean? 编辑:由于我的速度很慢,可以被几个答案击败,我会添加一些东西,这样我的答案不仅仅是前面的答案:
i, temp3
究竟是什么意思? Well, the C99 standard explains: 那么,C99标准解释说:
"The left operand of a comma operator is evaluated as a void expression; there is a sequence point after its evaluation. Then the right operand is evaluated; the result has its type and value.97) If an attempt is made to modify the result of a comma operator or to access it after the next sequence point, the behavior is undefined." “逗号运算符的左操作数被计算为void表达式;在评估之后有一个序列点。然后评估右操作数;结果有其类型和值.97)如果尝试修改结果一个逗号运算符或在下一个序列点之后访问它,行为是未定义的。“
So Table[i, temp3]
means "evaluate i, then access element number temp3 in Table
. Thus the compiler warns you that the i isn't doing anything (since evaluating i doesn't produce any side-effects). 所以
Table[i, temp3]
意思是“评估i,然后在Table
访问元素编号temp3。因此编译器会警告你我没有做任何事情(因为评估我没有产生任何副作用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.