I need to implement a 32-bit Fixed-point on a 16-bit system. My compiler seems to be giving me an "warning: integer overflow in expression". I'm not sure what I'm missing anything :S . I'll provide a dumbed down version of my code below. Any advice would be appreciate :)
#include <stdint.h>
typedef int32_t Q22;
#define Q22base 512
#define Q22_Convert(_a) ((Q22)(_a*Q22base))
int main (){
// a bunch of code that does stuff goes here
Q22 variable1=0;
variable1 = Q22_Convert(some_value1) - Q22_Convert(some_value1);
return 0;
}
Your Q22base
is 16-bit on a 16-bit int
system, you need to cast it to Q22
so your *
expression is done in at least a 32-bit type.
#define Q22_Convert(_a) ((Q22)(_a * (Q22) Q22base))