Math Issue


During development I found that I was subtracting two integer type variables and putting the result in a long type, my experience is the compiler will either complain or just cast it.  I found that if I took the result and defined it as an int it would work, BUT if I typecast the result from int to long to be passed to the long version, it would break without saying there was an Error or Warning (or Info).

Is this the expected bahaviior? Why does CCS not flag it?

The reality is that the motor control loop i am development ends up with wrong result (the difference value) and does not work.

See attached

4 Replies

  • I suggest you read this app note.  It describes the proper way to perform a 16x16 to 32 multiply.  That may not be the exact problem you have.  But, at a conceptual level, I think it is close enough.

    Thanks and regards,


    TI C/C++ Compiler Forum Moderator
    Please click This Resolved My Issue on the best reply to your question
    The CCS Youtube Channel
     has short how-to videos
    Compiler Wiki answers most common questions
    Track an issue with SDOWP. Enter your bug id in the Search box.

  • In reply to George Mock:



    I read the Application Report SPRA683 and didn't see a reason for my problems, one of the situations I've had was subtracting one int from another and assigning the result to a long the compiler didn't report an error, warning or info about the operation and failed to pass the result to the variable.  But typecasting the int to a long didn't solve the problem.
    Currently I've had a partial failure of the sprintf function in the standard string library, formatting an integer to string using this function is returning a string that doesn't represent the decimal value passed to it.  We are getting letters and unprintable characters, however in another function in the same project and the same module doing almost the same thing is working correctly.
  • In reply to DerekG:

    Are you perhaps using MSP compiler version 4.0.1?

  • In reply to DerekG:

    I'm having trouble picturing the failure scenario for subtraction.  Could you post a compilable test case where the compiler does not behave as you want it to?