Search code examples
cpic32

If statement is skipped


I have a very interesting problem come up while programming in MPLAB IDE v8.92. This is just a snipit of the code but this is where the problem is occuring:

struct data
{
  INT32 value;
};

struct data array[8] = {{0},{0},{0},{0},{0},{0},{0},{0}}; 
INT32 IOC[8];
INT32 IOD[8];


for ( byte i = 0; i<8; i++)
{
#ifdef DAC
  IOC[i] = 0;
  IOD[i] = 24;
  if(array[i].value == 0) array[i].value == 1;
#endif
}

The code builds with no errors and when I step through this part of the code using a ICD 3 debug, IOC and IOD are assigned correctly but the if statement is skipped! i.e. the debugger does not even stop on it. Any ideas what might have happened?


Solution

  • Always compile with -Wall -Werror. Your statement would have been flagged at compile time: warning: statement with no effect [-Wunused-value]