From 2004bbdb0298d7a2ce9aa274e4a9bbdd22792567 Mon Sep 17 00:00:00 2001 From: Marcus Müller Date: Sat, 4 Jun 2016 16:10:54 +0200 Subject: octoclock: Fix multi-line #define statements Now, use `do{...} while(0)` to pack multiple statements into a single one that isn't fragile. Currently ``` if(state_just_right) OCTOCLOCK_SEND_AND_RECV(all,the,options); ``` would introduce annoying bugs. Generally, there's no good reason this is a `#define` rather than a C/C++ function. The `OCTOCLOCK_PACKET_MATCHES` should probably be a C function, too, or simply an overloaded `==` operator on to `const octoclock_packet_t&`. --- host/lib/usrp_clock/octoclock/common.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'host/lib/usrp_clock') diff --git a/host/lib/usrp_clock/octoclock/common.h b/host/lib/usrp_clock/octoclock/common.h index 5861bc4b1..89fec9ce5 100644 --- a/host/lib/usrp_clock/octoclock/common.h +++ b/host/lib/usrp_clock/octoclock/common.h @@ -25,14 +25,16 @@ */ #ifdef __cplusplus -#define UHD_OCTOCLOCK_SEND_AND_RECV(xport, pkt_code, pkt_out, len, data) pkt_out.proto_ver = OCTOCLOCK_FW_COMPAT_NUM; \ - pkt_out.code = pkt_code; \ - xport->send(boost::asio::buffer(&pkt_out, sizeof(octoclock_packet_t))); \ - len = xport->recv(boost::asio::buffer(data), 2); - -#define UHD_OCTOCLOCK_PACKET_MATCHES(pkt_code, pkt_out, pkt_in, len) (len > offsetof(octoclock_packet_t, data) and \ - pkt_in->sequence == pkt_out.sequence and \ - pkt_in->code == pkt_code) +#define UHD_OCTOCLOCK_SEND_AND_RECV(xport, pkt_code, pkt_out, len, data) do {\ + pkt_out.proto_ver = OCTOCLOCK_FW_COMPAT_NUM; \ + pkt_out.code = pkt_code; \ + xport->send(boost::asio::buffer(&pkt_out, sizeof(octoclock_packet_t))); \ + len = xport->recv(boost::asio::buffer(data), 2);\ + } while(0) + +#define UHD_OCTOCLOCK_PACKET_MATCHES(pkt_code, pkt_out, pkt_in, len) (len > offsetof(octoclock_packet_t, data) and \ + pkt_in->sequence == pkt_out.sequence and \ + pkt_in->code == pkt_code) extern "C" { #endif -- cgit v1.2.3