cancel
Showing results for 
Search instead for 
Did you mean: 

STM Compiler & & Operator

CYBR
Associate II

I am trying to understand what I am doing wrong here. The following image was captured during a debug session to show strange behaviour.

2024-06-07_14-48-35.png

In the If statement ap->enable and ap->active are both true, but ap->relay_map is 0, as shown on the right, so this should evaluate to false. So why does the processor execute the statement within the brackets (shown by the green highlight) since the If fails? It actually crashes the processor because the index evaluates to -1 which is out of bounds of the relays array.

10 REPLIES 10

I have managed to prove that although the debugger actually looks like it steps to that line under these particular circumstances, in fact it does not execute the statement it steps to.

I put a line in between to turn on the LED. It steps to that line 10 below, but doesn't execute it, the LED does not turn on.

So apologies for wasting everyone's time. This is just an artefact of the debugger operation and not real.

 

 

	    	for(ai=0;ai<(sizeof(Alarms)/sizeof(AlarmType *));ai++)
	    	{
	    		//this process effectively does an OR, so multiple alarms can share one relay
	    		ap=Alarms[ai];
	    		if(ap->enable == true)
	    			if(ap->active == true)
	    			{
	    				if(ap->relay_map > 0)
						{
		    				HAL_GPIO_WritePin(GPIOC, LED_USER2_Pin, GPIO_PIN_RESET); //Turn Alarm LED on
							relays[ap->relay_map-1].relay_state=true;
						}
	    			}
	    	}