These macros in question were modifying variables outside of their
parameter listing. As the macros were also used in places where using
some of the variables don't make any sense, the were also some
compiler warning that were introduced since gcc version 4.6:
contour-protocol.c: In function ‘contour_read_entry’:
contour-protocol.c:296:6: warning: variable ‘j’ set but not used [-Wunused-but-set-variable]
As there are so many calls to the macros it makes sense to replace
them with static functions. This also cures the compiler
warning. Another plus side is that now using the macro should not have
any hard to miss side effects to other variables.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
-#define SET_FIRST_BYTE(byte) \
- do { \
- memset(&msg.data, 0, sizeof(msg.data)); \
- msg.data[4] = (byte); \
- j = 5; \
- } while (0)
-
-#define SET_BYTE(idx, byte) \
- do { \
- msg.data[(idx) + 4] = (byte); \
- j = (idx) + 1; \
- } while (0)
+static void set_first_msg_byte(struct msg *msg, int *idx, char byte)
+{
+ memset(msg->data, 0, sizeof(msg->data));
+ msg->data[4] = (byte);
+
+ *idx = 5;
+}
+
+static void set_msg_byte(struct msg *msg, int *idx, int where, char byte)
+{
+ msg->data[where + 4] = byte;
+ *idx = where + 1;
+}
#define SET_BYTES(byte) msg.data[j++] = (byte)
#define SET_BYTES(byte) msg.data[j++] = (byte)
msg.direction = OUT;
usleep(100 * 1000);
msg.direction = OUT;
usleep(100 * 1000);
+ set_first_msg_byte(&msg, &j, 0x01);
SET_BYTES(0x04);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(250 * 1000);
SET_BYTES(0x04);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(250 * 1000);
+ set_msg_byte(&msg, &j, 1, 0x15);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 0x05);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
+ set_first_msg_byte(&msg, &j, 0x02);
SET_BYTES(byte1);
SET_BYTES('|');
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
SET_BYTES(byte1);
SET_BYTES('|');
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, byte2);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
msg.direction = OUT;
read_msgs(fd);
msg.direction = OUT;
read_msgs(fd);
+ set_first_msg_byte(&msg, &j, 0x01);
SET_BYTES(0x04);
send_msg_with_proggress_note(&msg, fd, uc);
usleep(100 * 1000);
SET_BYTES(0x04);
send_msg_with_proggress_note(&msg, fd, uc);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 0x06);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
+ set_msg_byte(&msg, &j, 1, 0x15);
for (i = 0; i < 6; i++) {
usleep(100 * 1000);
send_msg_with_proggress_note(&msg, fd, uc);
for (i = 0; i < 6; i++) {
usleep(100 * 1000);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 0x05);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
send_pattern(fd, uc, 'W', 'K');
usleep(100 * 1000);
send_pattern(fd, uc, 'W', 'K');
usleep(100 * 1000);
+ set_first_msg_byte(&msg, &j, 0x08);
SET_BYTES('O');
SET_BYTES('b');
SET_BYTES('p');
SET_BYTES('O');
SET_BYTES('b');
SET_BYTES('p');
read_msgs(fd);
usleep(410 * 1000);
read_msgs(fd);
usleep(410 * 1000);
+ set_first_msg_byte(&msg, &j, 0x02);
SET_BYTES('R');
SET_BYTES('|');
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
SET_BYTES('R');
SET_BYTES('|');
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 'Y');
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 'W');
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 'K');
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 'C');
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
send_pattern(fd, uc, 'R', 'Z');
usleep(100 * 1000);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
send_pattern(fd, uc, 'R', 'Z');
usleep(100 * 1000);
+ set_first_msg_byte(&msg, &j, 0x01);
SET_BYTES(0x04);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
SET_BYTES(0x04);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 0x15);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 0x05);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 0x04);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
read_msgs(fd);
usleep(100 * 1000);
read_msgs(fd);
usleep(100 * 1000);
+ set_msg_byte(&msg, &j, 1, 0x06);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
int j;
msg.direction = OUT;
int j;
msg.direction = OUT;
- SET_FIRST_BYTE(0x01);
- SET_BYTE(1, 0x06);
+ set_first_msg_byte(&msg, &j, 0x01);
+ set_msg_byte(&msg, &j, 1, 0x06);
send_msg(&msg, fd, uc);
read_and_verify(in, fd);
send_msg(&msg, fd, uc);
read_and_verify(in, fd);