Red Error: Non terminating loop

11 visualizaciones (últimos 30 días)
Phani Kakarala
Phani Kakarala el 7 de Mayo de 2019
Respondida: John Boyd el 8 de En. de 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.

Respuestas (1)

John Boyd
John Boyd el 8 de En. de 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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by