MATLAB Answers

Red Error: Non terminating loop

12 views (last 30 days)
Phani Kakarala
Phani Kakarala on 7 May 2019
Answered: John Boyd on 8 Jan 2020
Struct PIE_Reg {
union PIECTRL_REG PIECCTRL;//Size of each union is uint16
union PIECTRL_REG1 PIECCTRL1;//Size of each union is uint16
union PIECTRL_REG2 PIECCTRL2;//Size of each union is uint16
union PIECTRL_REG3 PIECCTRL3;//Size of each union is uint16
};
volatile struct PIE_Reg ASILBCheckPieCtrlChanges;
volatile struct PIE_Reg PieCtrlReg;
Func example(void){
uint8 index;
volatile uint16 *ASILBCheck = &ASILBCheckPieCtrlChanges.PIECCTRL.all;
volatile uint16 *piectrlpointer = &PieCtrlReg.PIECCTRL.all;
for(index = 0; index < 4; index++){
ASILBCheck[index] = piectrlpointer[index];
}
}
In function example at for loop I am getting the Red Error with following message:
The loop is infinite or contains runtime error
Loop fails due to a runtime error(maximum number of iterations:2)
Can you give me solution how to fix this and explain me what went wrong in the above code.

  0 Comments

Sign in to comment.

Answers (1)

John Boyd
John Boyd on 8 Jan 2020
You set your pointer to the address of a field, and when you go past the field it reports a pointer out of bounds. The solution is to either set the pointer to the struct base address (if possible) or use the "Enable pointer arithmetic across fields" option under Check Behavior in the Pointer section near the bottom of the panel. If you enable this setting it likely will result in more orange results elsewhere in the program, so I recommend using the base address in the code if that is possible.

  0 Comments

Sign in to comment.

Sign in to answer this question.


Translated by