Warning: instruction is not valid (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 ++), a warning (the operator does not work) is issued for lines 92 and 95 (indicated in the snippet above)

I do not understand why they do not work, although I looked at him for a while - I could do with a second pair of eyes to see if they could determine what I was missing.

+4
source share
6 answers

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

The first statement in the for loop is executed once, that is, when you enter the loop first. Since you want to include row number zero for all subsequent columns, you must set the 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); } } } } } 
+7
source

This is about the col and row parts in the loop initialization part. These statements do nothing. Just delete it:

 for( ; col < num_cols; col++) 
+6
source
 for( col; col < num_cols; col++ ) col; 

It does not affect. You must assign something to him or not write at all. Since you are assigning it from your loop, you just need to leave it empty ; in this place or use in a loop.

+5
source

You get these warnings because the initialization statements in for loops are expressions that do nothing:

 for(col; col < num_cols; col++) // line 92: "col" has no effect for(row; row < num_rows; row++) // line 95: "row" has no effect 

Since you have already initialized these variables outside the loop, you can omit them from the for statement:

 for(; col < num_cols; col++) // line 92 for(; row < num_rows; row++) // line 95 

However, the best thing here is to initialize the variables in the for loops themselves, and not outside of them:

 // 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); } } } 
+2
source

If you really want to enter variable names in your loop (how can the hint be?), Try changing:

 for( col; col < num_cols; col++ ) 

like that:

 for( col = col; col < num_cols; col++ ) 

for both lines. He has to do this work.

0
source

My guess: you can just use

 for(; col < num_cols; col++ ) // Line 92 

and

 for (; row < num_rows; row++) { // Line 95 
0
source

All Articles