This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Inexecutable statements inside switch case

I have a segment of codes as follows. 'app' is a structure variable.

The code can successfully pass the compiling process and run but contains some inexecutable important commands, which can't be recognized by compiler, e.g.app.bT = TRUE. Besides, there are some disordered jump inside the switch, e.g. jumping from case 1 to case 5 without executing "break" in case 1.

app.bT=FALSE;

do {

switch ( ix )

{

case 0: if ( app.f0< app.fB1 ) app.bT = TRUE; break;

case 1: if (( app.fB1 <= app.f0 )&&( app.f0<= app.fB2 ) ) {if ( app.fC1 > ( ( app.fM1 * app.f0 ) +( app.f_Allowed - app.fM1* app.fB2 ) ) ) app.bT= TRUE; } break;

case 2: if ( app.f0>app.f_Allowed) app.bT = TRUE;

break;

case 3: if (( app.f0 <= app.fB4 ) ) { if ( app.fT > ( ( app.fM2 * app.f0 ) +( app.f_Allowed -app.fM2*app.fB3 ) ) ) app.bT = TRUE; } break;

case 4: if ( app.f0> app.fB4 ) app.bT = TRUE; break; default: break;

}

ix++;

}

while ( ix < 5 && app.bT == FALSE );

I think it's the internal error of C51 since there are few other explanation for this strange problem but I still don't want to believe that's true.
Would you please give me an answer? Thank you for your help.

Parents
  • "No the source code has never been changed."

    Of course not - optimisation does not affect the source code!
    Optimisation is performed on the Object code!

    "When I increase the optimization level from 7 to 8, the problem occured again."

    What problem?
    When you use high-level optimisations like this, you will never be able to simply follow the source lines in generated machine code - that's the whole point!
    An optimiser will always re-order code, remove unnecessary code, etc, etc to achieve its goal!
    That's what optimisers do!

    "I observed is that the execution sequence..."

    The execution sequence is irrelevant, and must be expected to change - see above.

    "...result produced were totally different"

    The final result, though, should be identical - aside from timing.

    If the final result is really different, then you most certainly do have a problem!
    In what way is the final result different?

Reply
  • "No the source code has never been changed."

    Of course not - optimisation does not affect the source code!
    Optimisation is performed on the Object code!

    "When I increase the optimization level from 7 to 8, the problem occured again."

    What problem?
    When you use high-level optimisations like this, you will never be able to simply follow the source lines in generated machine code - that's the whole point!
    An optimiser will always re-order code, remove unnecessary code, etc, etc to achieve its goal!
    That's what optimisers do!

    "I observed is that the execution sequence..."

    The execution sequence is irrelevant, and must be expected to change - see above.

    "...result produced were totally different"

    The final result, though, should be identical - aside from timing.

    If the final result is really different, then you most certainly do have a problem!
    In what way is the final result different?

Children
  • Thank you for reminding me about these issues. I have learned a lot from what you told me.

    This time I got the point you have tried to tell me. What I have traced is the optimized sequence and the result should be the same. I admit that what you said is right.

    For proprietary consideration, I am sorry I can't post the whole source codes.

  • "I am sorry I can't post the whole source codes"

    The fact that it was just an extract wasn't the issue - the real issue was that it was unreadable, because you hadn't followed the instructions about using the tags...