warning: variable set but unused

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
}
Last edited on
> 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.
closed account (E0p9LyTq)
The warnings are advisory, they are not fatal to your program being compiled and run.

You are only assigning values to turn and ret, not using the values as return values or comparisons in if statements, etc.

Maybe line 38 should be return ret; instead of return 0;?
Topic archived. No new replies allowed.