当前位置: 首页 > 工具软件 > unused > 使用案例 >

[-Werror=unused-but-set-variable] 报错的解决

费承载
2023-12-01

错误: 变量‘xxx’被设定但未被使用 [-Werror=unused-but-set-variable]

warning: variable set but unused - C++ Forum

出现这个警告的原因可能是,基本上,你移除这个变量也不会对你的程序造成什么影响。

warning: variable 'ret' set but not used [-Wunused-but-set-variable]
warning: variable 'turn' set but not used [-Wunused-but-set-variable]

receiving these errors even though I am using them

Please guide me to the solution of these warnings!

I use turn on lines: 10, 17 25

I use ret on line: 33

int OlsonAttack(int mode, int opponent) //ATTACK FUNCTION
{
    int column;
    char row;
    int ret;

    //******    STATUS VERIABLES    ******//
    static int board[BS_GRID_ROWS][BS_GRID_COLS]; // board will not change

    static bool turn; //allows turn to end || not to fire > once
    static bool hit; //fired is for shot per turn
    //***********************************//

    switch(mode) {
    case BS_MODE_NEW_GAME: //NEW GAME
     
        turn = true;

        for (row = 0; row < BS_GRID_ROWS; row++) //search/increment row
            for(column = 1; column < BS_GRID_COLS; column++) //search increment column
               board[row+'A'][column] = 0;
        break;

    case BS_MODE_CONTINUE_GAME: //CONTINUE GAME (no error)
    turn = true;
    if (!hit) {
        do {
            row = rand() % BS_GRID_ROWS;
            column = rand() % BS_GRID_COLS;
        }while (board[row+'A'][column] == 1);

        board[row+'A'][column] = 1; //Marks a probed unit of space on array
        ret = fire[opponent](row + 'A', column + 1);

    }
        break;
    }
    return 0;
}

 > I use turn on lines: 10, 17 25
line 10: static bool turn; definition, not a use
line 17 and 25:turn = true; setting, not a use

> I use ret on line: 33
ret = fire[opponent](row + 'A', column + 1); setting, not a use


Bascally, if you remove those two variables, the behaviour of your program should not change.

 类似资料: