Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

Why "for" loop expression has no effect ?

We used Keil tools to compile our embedded c++ code.

for ( i = 0, idx_reg_curr = j ;  i < 10,  idx_reg_curr < (j+10) ;   i++,  idx_reg_curr++ )

In above for loop, I get the following compile warning:

warning:   #174-D:  expression has no effect


Why doesn't this expression has effect ?
Avatar of naseeam
naseeam
Flag of United States of America image

ASKER

for (short j = 0; j < 40; j+= 10)
{
   for (i = 0, idx_reg_curr = j; i < 10, idx_reg_curr < (j+10); i++, idx_reg_curr++)
   {
       SCODesc[i * 2] = (char)(responseBuffer[idx_reg_curr] & 0xFF);
       SCODesc[i * 2 + 1] = (char)(responseBuffer[idx_reg_curr] >> 8);
   }

   ParameterManager::GetParameterById((ParameterId)(Parameters::Info[idx_id++].Id))->setValue((char*)SCODesc, 20);

}

Open in new window

Avatar of sarabande
i < 10,  idx_reg_curr < (j+10)

exchange the expression by

 i < 10 ||  idx_reg_curr < (j+10)

Open in new window



if you want to have both counters to be below the upper boundary.

otherwise you may use logical &&.

note, the , (comma) allows to execute two statements. but putting a comma in a logical expression has no effect. the compiler only would check the first expression.

Sara
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of naseeam

ASKER

Problem solved and explained very quickly.  Thank you very much!