From 0862a3c512717468fe36d0dfb9716a2b8d80f089 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 16 Jun 2020 13:33:40 +0200 Subject: [PATCH] core/include: Don't use 64 bit for MHZ & MiB macros Those macros are all about convenience. However, always using 64 bit makes casts nececcary that goes against the idea of having a convenience macro. E.g. when printing a frequency in KHZ one might want to do printf("freq: %lu kHz\n", freq / KHZ(1)); leads to an error > error: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'long long unsigned int' Now we would have to cast - `%llu` is not available with newlib-nano and wholly uneccecary. Only use 64 bit artithmetic where necessary (GHZ, GiB), not for smaller units. --- core/include/macros/units.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/include/macros/units.h b/core/include/macros/units.h index 0defef090d..daa04ff4c5 100644 --- a/core/include/macros/units.h +++ b/core/include/macros/units.h @@ -26,7 +26,7 @@ /** * @brief A macro to return the bytes in x KiB */ -#define KiB(x) ((unsigned long long)(x) << 10) +#define KiB(x) ((unsigned long)(x) << 10) /** * @brief A macro to return the bytes in x MiB @@ -36,17 +36,22 @@ /** * @brief A macro to return the bytes in x GiB */ -#define GiB(x) (MiB(x) << 10) +#define GiB(x) ((unsigned long long)MiB(x) << 10) /** * @brief A macro to return the Hz in x kHz */ -#define KHZ(x) ((x) * 1000ULL) +#define KHZ(x) ((x) * 1000UL) /** * @brief A macro to return the Hz in x MHz */ -#define MHZ(x) (KHZ(x) * 1000ULL) +#define MHZ(x) (KHZ(x) * 1000UL) + +/** + * @brief A macro to return the Hz in x GHz + */ +#define GHZ(x) (MHZ(x) * 1000ULL) #ifdef __cplusplus }