Browse Source

utils: Fix unused-value warnings

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: 0347a3df44 ("* PR #76 updated debug messages: now 5 different levels are available * fixed CRC loop issue")
pull/1191/head
Alexander Dahl 2 years ago
parent
commit
26c3de3a40
  1. 12
      src/utils/dbg.h
  2. 8
      src/utils/helper.h

12
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 {

8
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);

Loading…
Cancel
Save