Preprocessor variables wrongly defined in Microchip's C99 header files
I want to preface a possible discussion in this thread by saying that I don't have extensive knowledge about C so my issue might seem trivial because I might be missing something. Honestly, it seems kind of clear to me but ya never know.
So in my project using Bosch sensors' BMP180 API, I am using the #define directive to create a few macro's:
/*! @brief Macros holding the bound values for the temperature in degree celsius */
#define BMP180_ST_PLAUSIBLE_TEMP_MIN UINT8_C(0)
#define BMP180_ST_PLAUSIBLE_TEMP_MAX UINT8_C(45)
/*! @brief Macros holding the bound values for the pressure in hPa */
#define BMP180_ST_PLAUSIBLE_PRESS_MIN UINT16_C(900)
#define BMP180_ST_PLAUSIBLE_PRESS_MAX UINT16_C(1100)
#define BMP180_ST_TEMPERATURE_RESOLUTION UINT8_C(10)
#define BMP180_ST_PRESSURE_RESOLUTION UINT8_C(100)
These macro's I use in the following conditional where pressure is uint32_t variable:
if ((pressure < (BMP180_ST_PLAUSIBLE_PRESS_MIN * BMP180_ST_PRESSURE_RESOLUTION)) ||
(pressure > (BMP180_ST_PLAUSIBLE_PRESS_MAX * BMP180_ST_PRESSURE_RESOLUTION)))
/* implausible pressure */
However, my compiler is giving me the following error:
warning: overflow in expression; result is -21072 with type 'int' [-Winteger-overflow]
which mathematically as I see it doesn't make sense since both are supposed to be unsigned long and the result can't go higher than 100000.
So I went to check UINT32_C() definition in xc8 v2.05 included header files and I saw the following:
#define UINT8_C(c) c
#define UINT16_C(c) c
#define UINT24_C(v) (v ## UL)
#define UINT32_C(c) c ## UL
#define UINT32_C(c) c ## U
Now check the preprocessor variables in bold. This is why I added that preface, because according to me these are wrongly defined. The MPLAB XC8 C Compiler User Guide for PIC pdf that comes with the download of xc8 v2.05 defines a few preprocessor macros that indicate some of the used compiler info. They are on page 162 and 163. They are __XC8, __XC, __XC_MODE_ and __XC_VERSION. There is no __XC8__ anywhere in the guide. I think that this variable was from a previous xc compiler, maybe a version predating v2.0.
Anyway, if I remove the UINT_C macro and just put UL after the constants, the compiler warning goes away. Question is, am I missing something?
post edited by sxanthony06 - 2019/07/20 07:07:55