Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: statement has no effect (C++)

Tags:

c++

I have the following code:

void CScriptTable::EnumReferences(asIScriptEngine *engine)
{
    if (m_table)
    {   
        // Call the gc enum callback for each nested table      
        size_t col = 0, row = 0, num_cols = m_table->numCols(), num_rows = m_table->numRows();

        for( col; col < num_cols; col++ )   // Line 92
        {   
            if (m_table->getColType(col) == COL_TABLE) {
                for (row; row < num_rows; row++){  // Line 95
                    Table * tbl = m_table->getTable(row, col);
                    engine->GCEnumCallback(tbl);
                }   
            }   
        }   
    }   
}

When compiling, (g++), the warning (statement has no effect) is issued for line 92 & 95 (indicated in the snippet above)

I can't see why they have no effect even though I have been staring at it for a while - could do with a second pair of eyes to see if they can spot what I'm missing.

like image 914
Homunculus Reticulli Avatar asked Nov 30 '22 03:11

Homunculus Reticulli


1 Answers

If guess you want to iterate over all columns and for each of them over all rows. so better change your code to something like this:

The first statement in the for loop is executed once, i.e. at the time the loop is entered at first. Since you want to include row number zero for all further columns you have to set row to 0 for each column:

void CScriptTable::EnumReferences(asIScriptEngine *engine)
{
    if (m_table)
    {   
        // Call the gc enum callback for each nested table      
        size_t num_cols = m_table->numCols(), num_rows = m_table->numRows();

        for(size_t col = 0; col < num_cols; col++ )   // Line 92
        {   
            if (m_table->getColType(col) == COL_TABLE) {
                for (size_t row = 0; row < num_rows; row++){  // Line 95
                    Table * tbl = m_table->getTable(row, col);
                    engine->GCEnumCallback(tbl);
                }   
            }   
        }   
    }   
}
like image 131
b.buchhold Avatar answered Dec 05 '22 12:12

b.buchhold