From 26c3de3a401b7d781a7302b6ee32157f187e8ed9 Mon Sep 17 00:00:00 2001 From: Alexander Dahl Date: Thu, 28 Sep 2023 09:06:25 +0200 Subject: [PATCH] utils: Fix unused-value warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When built with -Wall the idiom `({ … })` leads to a "value computed is not used" warning. That notation produces a compound statement that acts as an expression with the value being the value of the last statement inside. For the switch statement it is not even clear what this value would be and it is never used anywhere (hence the warning). For the CP_ macros it would be one byte out of four right? Makes no sense either. You would have to assign that value to something, but then you would use a real function with a return type, because that is easier to understand anyways. So why not use the usual way to create a void function like preprocessor macro in C/C++ by using a do-while-loop with a false condition. Warning disappears. Link: https://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html Fixes: 0347a3df44d7 ("* PR #76 updated debug messages: now 5 different levels are available * fixed CRC loop issue") --- src/utils/dbg.h | 12 ++++++------ src/utils/helper.h | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/dbg.h b/src/utils/dbg.h index 6c861329..9e754ba6 100644 --- a/src/utils/dbg.h +++ b/src/utils/dbg.h @@ -148,7 +148,7 @@ #define PVERBLN(str) #endif -#define DPRINT(level, str) ({\ +#define DPRINT(level, str) do {\ switch(level) {\ case DBG_ERROR: PERR(str); break; \ case DBG_WARN: PWARN(str); break; \ @@ -156,13 +156,13 @@ case DBG_DEBUG: PDBG(str); break; \ default: PVERB(str); break; \ }\ -}) +} while (0) -#define DPRINT_IVID(level, id) ({\ +#define DPRINT_IVID(level, id) do {\ DPRINT(level, F("(#")); DBGPRINT(String(id)); DBGPRINT(F(") "));\ -}) +} while (0) -#define DPRINTLN(level, str) ({\ +#define DPRINTLN(level, str) do {\ switch(level) {\ case DBG_ERROR: PERRLN(str); break; \ case DBG_WARN: PWARNLN(str); break; \ @@ -170,7 +170,7 @@ case DBG_DEBUG: PDBGLN(str); break; \ default: PVERBLN(str); break; \ }\ -}) +} while (0) /*class ahoyLog { diff --git a/src/utils/helper.h b/src/utils/helper.h index e1702877..252ca9fe 100644 --- a/src/utils/helper.h +++ b/src/utils/helper.h @@ -20,21 +20,21 @@ static Timezone gTimezone(CEST, CET); #define CHECK_MASK(a,b) ((a & b) == b) -#define CP_U32_LittleEndian(buf, v) ({ \ +#define CP_U32_LittleEndian(buf, v) do { \ uint8_t *b = buf; \ b[0] = ((v >> 24) & 0xff); \ b[1] = ((v >> 16) & 0xff); \ b[2] = ((v >> 8) & 0xff); \ b[3] = ((v ) & 0xff); \ -}) +} while (0) -#define CP_U32_BigEndian(buf, v) ({ \ +#define CP_U32_BigEndian(buf, v) do { \ uint8_t *b = buf; \ b[3] = ((v >> 24) & 0xff); \ b[2] = ((v >> 16) & 0xff); \ b[1] = ((v >> 8) & 0xff); \ b[0] = ((v ) & 0xff); \ -}) +} while (0) namespace ah { void ip2Arr(uint8_t ip[], const char *ipStr);