I have the following code, for an embedded platform where an int is 16 bits and a long int is 32 bits:
#define MULTIPLIER 0x1000
static void my_function(uint16_t i, void *p)
{
uint32_t start = MULTIPLIER * i;
...
}
My compiler gives me the warning:
Warning 1 : lower precision in wider context: '*'
for this line.
What does this really mean? I can make the warning go away by changing the #define to
#define MULTIPLER 0x1000ul
(explicitly making it an unsigned long) but I would like to understand the warning.
It’s warning you that the multiplication will take place using 16-bit values, and the 16-bit result will then be converted to a 32-bit result. This might not be what you expect (the 16-bit multiplication might overflow), hence the warning.
This forum posting covers the issue