From 39ccdf3234b7ba57b0179d7a931543eaa0aa8703 Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Sun, 1 May 2011 23:27:18 +0200 Subject: [PATCH] Improve handling of arguments of the macros --- src/modbus.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modbus.h b/src/modbus.h index ad9ebfa..ad40da0 100644 --- a/src/modbus.h +++ b/src/modbus.h @@ -187,14 +187,14 @@ int modbus_reply_exception(modbus_t *ctx, const uint8_t *req, * UTILS FUNCTIONS **/ -#define MODBUS_GET_HIGH_BYTE(data) ((data >> 8) & 0xFF) -#define MODBUS_GET_LOW_BYTE(data) (data & 0xFF) -#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) ((tab_int16[index] << 16) + tab_int16[index + 1]) -#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) ((tab_int8[index] << 8) + tab_int8[index + 1]) +#define MODBUS_GET_HIGH_BYTE(data) (((data) >> 8) & 0xFF) +#define MODBUS_GET_LOW_BYTE(data) ((data) & 0xFF) +#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) ((tab_int16[(index)] << 16) + tab_int16[(index) + 1]) +#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) ((tab_int8[(index)] << 8) + tab_int8[(index) + 1]) #define MODBUS_SET_INT16_TO_INT8(tab_int8, index, value) \ do { \ - tab_int8[index] = value >> 8; \ - tab_int8[index + 1] = value & 0xFF; \ + tab_int8[(index)] = (value) >> 8; \ + tab_int8[(index) + 1] = (value) & 0xFF; \ } while (0) void modbus_set_bits_from_byte(uint8_t *dest, int address, const uint8_t value); -- libgit2 0.21.4