Red Error: Non terminating loop

조회 수: 6 (최근 30일)
Phani Kakarala
Phani Kakarala 2019년 5월 7일
답변: John Boyd 2020년 1월 8일
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.

답변 (1개)

John Boyd
John Boyd 2020년 1월 8일
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