本文介绍了警告:逗号右侧的操作数不起作用gcc 4.4.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux下,我需要你的帮助以下警告gcc 4.4.7

  for(int iLoop1 = 0; iLoop1< iLoopN;!++ iLoop1,++ iLoop2,iIsOk)

我有以下警告从未来

 错误:逗号右操作数没有效果

我已经阅读了逗号运算符上的wiki页面,但我不明白这个问题



编辑:
有效!iIsOk没有做任何
我测试了以下代码

  //示例程序
#include< iostream>
#include< string>
#include< iostream>

int main()
{

int iIsOk = 0; (int iLoop1 = 0; iLoop1

{
std :: cout<< IsOk =<< iIsOk<<的std :: ENDL;
}

。对于(INT iLoop1 = 0; iLoop1&2; iLoop1 ++,iIsOk = iIsOk!)
{
的std ::法院<< IsOk2 =<< iIsOk<<的std :: ENDL;


$ / code $ / pre
$ b $输出:

  IsOk = 0 
IsOk = 0
IsOk2 = 0
IsOk2 = 1


解决方案 c $ c>!iIsOk ;即删除它将对程序完全没有影响。



您的有用编译器会警告您。



您的意思是在循环中写入!iIsOk 作为停止条件的一部分:



iLoop1< iLoopN&& iIsOk



切换使用

iLoop1 ++,iIsOk =!iIsOk



或华丽(其亲自我发现清晰,因为有较少的变量重复)



iLoop1 ++,iIsOk ^ = true


I need your help for the following warning in Linux gcc 4.4.7

for (int iLoop1= 0; iLoop1< iLoopN; ++iLoop1, ++iLoop2, !iIsOk)

I have the following warnings coming from the last argument after the last comma

error: right-hand operand of comma has no effect

I have read the wiki page on comma operator but I do not understand the problemhttps://en.wikipedia.org/wiki/Comma_operator

EDIT :effectively !iIsOk does nothingI have tested the following code

// Example program
#include <iostream>
#include <string>
#include <iostream>

int main()
{

    int iIsOk = 0;

    for (int iLoop1 = 0; iLoop1 < 2; iLoop1++, !iIsOk)
    {
       std::cout << "IsOk=" << iIsOk << std::endl;
    }

      for (int iLoop1 = 0; iLoop1 < 2; iLoop1++, iIsOk = !iIsOk)
    {
       std::cout << "IsOk2=" << iIsOk << std::endl;
    }
}

Output:

IsOk=0
IsOk=0
IsOk2=0
IsOk2=1
解决方案

!iIsOk although evaluated, does not do anything; i.e. removing it will have absolutely no effect on the program.

Your helpful compiler is warning you of this.

Did you mean to write !iIsOk as part of the stopping condition in the loop:

iLoop1< iLoopN && iIsOk

or toggle it using

iLoop1++, iIsOk = !iIsOk

or the flashier (which personally I find clearer since there are fewer variable repeats)

iLoop1++, iIsOk ^= true

这篇关于警告:逗号右侧的操作数不起作用gcc 4.4.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:32