cancel
Showing results for 
Search instead for 
Did you mean: 

How to correct my code in case of an abnormal branch

Kim.Andy
Associate III
Posted on January 19, 2018 at 09:51

Hi.

The below function is called by a few events.

int sendDeviceEvent(int idx, char type){

 int result;

 char *buff;

 if(type == TYPE_REG)

 {

 makeRegInfo(idx,buff);

 sendInfoToSlave(buff, sizeof(sRegPoll));

 }

 else if(type == TYPE_128)

 {

 make128Info(idx,buff);

 sendInfoToSlave(buff, sizeof(s128Poll));

 }

 else if(type == TYPE_INV)

 {

 makeInvInfo(idx,buff);

 sendInfoToSlave(buff, sizeof(sInvPoll));

 }

 return waitInfoFromSlave(idx);

}

If this function is called by EVENT_A(

sendDeviceEvent(1,

TYPE_REG

)), 

sendInfoToSlave(buff, sizeof(sRegPoll)) is executed normally.

But If this function is called by EVENT_B(

sendDeviceEvent(1,

TYPE_REG

)),  

sendInfoToSlave(buff, sizeof(sRegPoll)) is not executed. That is, is not branched to sendInfoToSlave().

Which point should I check? (IAR, ST32F2xx series)

Thanks.

4 REPLIES 4
Andrew Neil
Chief II
Posted on January 19, 2018 at 09:58

So have you stepped through it in the debugger to see exactly what's happening?

Any particular reason for not using a switch here?

Danish1
Lead II
Posted on January 19, 2018 at 10:43

How strongly do you know that TYPE_REG is the same thing in both calls?

My guess is that somewhere in your code you have #define TYPE_REG value

Are EVENT_A and EVENT_B in the same (c or c++) source-code file?

If they are from different source-code files, it is possible that the #defines are different - unless you put the #define in a single header that you #include in both source-code files.

Please don't feel insulted that I raised this as a possibility. It is an easy mistake to make.

Danish

Posted on January 19, 2018 at 11:09

Hi, Danish.

By EVENT_A and EVENT_B, the function, 

makeRegInfo(idx,buff) is executed normally.

Only the function, 

sendInfoToSlave(buff, sizeof(sRegPoll) is not executed.

So it is a mistake to think that the definition of 

TYPE_REG would be wrong.

Thanks.

Posted on January 19, 2018 at 12:35

So, again, have you stepped through it in the

debugger

to see exactly what's happening?