Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.

Commit 756aa52

Browse files
t-bbourtemb
authored andcommitted
Pollthread: Fix multiline macro definitions (#451)
GCC 8.1.0 outputs /home/firma/devel/cppTango/cppapi/server/pollthread.cpp:1269:11: warning: macro expands to multiple statements [-Wmultistatement-macros] T_ADD(ite_next->wake_up_date,min_delta - diff); ^~~~~~~~ /home/firma/devel/cppTango/cppapi/server/pollthread.h:196:2: note: in definition of macro ‘T_ADD’ A.tv_usec = A.tv_usec + B; \ ^ /home/firma/devel/cppTango/cppapi/server/pollthread.cpp:1268:4: note: some parts of macro expansion are not guarded by this ‘if’ clause if (diff < min_delta) ^~ which is correct as T_ADD is a multiline macro and thus should be enclosed in do { } while(0) as described in https://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html#Swallowing-the-Semicolon.
1 parent 9ff17bb commit 756aa52

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

cppapi/server/pollthread.h

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -183,30 +183,42 @@ class PollThread: public omni_thread
183183
// Three macros
184184
//
185185

186-
#define T_DIFF(A,B,C) \
187-
long delta_sec = B.tv_sec - A.tv_sec; \
188-
if (delta_sec == 0) \
189-
C = B.tv_usec - A.tv_usec; \
190-
else \
191-
{ \
192-
C = ((delta_sec - 1) * 1000000) + (1000000 - A.tv_usec) + B.tv_usec; \
193-
}
194-
195-
#define T_ADD(A,B) \
196-
A.tv_usec = A.tv_usec + B; \
197-
while (A.tv_usec > 1000000) \
198-
{ \
199-
A.tv_sec++; \
200-
A.tv_usec = A.tv_usec - 1000000; \
201-
}
202-
203-
#define T_DEC(A,B) \
204-
A.tv_usec = A.tv_usec - B; \
205-
if (A.tv_usec < 0) \
206-
{ \
207-
A.tv_sec--; \
208-
A.tv_usec = 1000000 + A.tv_usec; \
209-
}
186+
#define T_DIFF(A,B,C) \
187+
do \
188+
{ \
189+
long delta_sec = B.tv_sec - A.tv_sec; \
190+
if (delta_sec == 0) \
191+
C = B.tv_usec - A.tv_usec; \
192+
else \
193+
{ \
194+
C = ((delta_sec - 1) * 1000000) + (1000000 - A.tv_usec) + B.tv_usec; \
195+
} \
196+
} \
197+
while(0)
198+
199+
#define T_ADD(A,B) \
200+
do \
201+
{ \
202+
A.tv_usec = A.tv_usec + B; \
203+
while (A.tv_usec > 1000000) \
204+
{ \
205+
A.tv_sec++; \
206+
A.tv_usec = A.tv_usec - 1000000; \
207+
} \
208+
} \
209+
while(0)
210+
211+
#define T_DEC(A,B) \
212+
do \
213+
{ \
214+
A.tv_usec = A.tv_usec - B; \
215+
if (A.tv_usec < 0) \
216+
{ \
217+
A.tv_sec--; \
218+
A.tv_usec = 1000000 + A.tv_usec; \
219+
} \
220+
} \
221+
while(0)
210222

211223
} // End of Tango namespace
212224

0 commit comments

Comments
 (0)