We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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?
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.
Thanks Per, that's it. Should have seen it; I guess that is what you get when you come to work with a flu and a fever...