Skip to main content
Kim.Andy
Associate II
January 19, 2018
Question

How to correct my code in case of an abnormal branch

  • January 19, 2018
  • 4 replies
  • 1281 views
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.

    This topic has been closed for replies.

    4 replies

    Andrew Neil
    Super User
    January 19, 2018
    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?

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Danish1
    Lead III
    January 19, 2018
    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

    Kim.Andy
    Kim.AndyAuthor
    Associate II
    January 19, 2018
    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.

    Andrew Neil
    Super User
    January 19, 2018
    Posted on January 19, 2018 at 12:35

    So, again, have you stepped through it in the

    debugger

    to see exactly what's happening?
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.