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

What is the source of the warning?

Hello,

I'm scanning a piece of legacy code with PC-lint. I get the following warning:

Warning 648: Overflow in computing constant for operation: 'multiplication'

for the following piece of code:

(unsigned int)(0-((full_pw+1)*2/10))

where

#define full_pw 19999              // for 100 Hz PWM signal

The playform is C166 based (int is 16 bit). I don't immediately see why this should generate a warning. Do you?

Parents
  • What happens if you tell the compiler and lint that your constant is unsigned, i.e.

    #define full_pw 19999u
    

    Note that the default data type for the compiler is int, unless the constant is so large that it must be unsigned. Your constant is below 32768, so it should be treated as an int. and 19999*2 is larger than 32767 which do represent an overflow.

Reply
  • What happens if you tell the compiler and lint that your constant is unsigned, i.e.

    #define full_pw 19999u
    

    Note that the default data type for the compiler is int, unless the constant is so large that it must be unsigned. Your constant is below 32768, so it should be treated as an int. and 19999*2 is larger than 32767 which do represent an overflow.

Children