C语言中"for"循环中的两个变量 [英] Two variables in a 'for' loop in C
本文介绍了C语言中"for"循环中的两个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一些代码,需要在for
循环中使用两个变量.下面的代码看起来还不错吗?
I am writing some code where I need to use two variables in a for
loop. Does the below code seem alright?
它确实给了我预期的结果.
It does give me the expected result.
for (loop_1 = offset,loop_2 = (offset + 2); loop_1 >= (offset - 190),loop_2 <= (190 + offset + 2); loop_1--,loop_2++)
{
if ( (*(uint8_t*)(in_payload + loop_1) == get_a1_byte(bitslip)) &&
((*(uint8_t*)(in_payload + loop_2) == get_a2_byte(bitslip)))
)
{
a1_count++;
}
}
但是我收到一个编译器警告,内容为:
But I am getting a compiler warning which says:
file.c:499:73:警告:逗号表达式的左侧操作数无效
file.c:499:73: warning: left-hand operand of comma expression has no effect
这是什么意思?
推荐答案
问题是测试条件:
loop_1 >= (offset - 190),loop_2 <= (190 + offset + 2)
这不会同时检查两个部分. (当然,但是只使用第二部分的结果.)
This does not check both parts. (Well, it does, but only the result of the second part is used.)
将其更改为
(loop_1 >= (offset - 190)) && (loop_2 <= (190 + offset + 2))
如果要同时检查两个条件.
if you want both conditions to be checked.
这篇关于C语言中"for"循环中的两个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文