[Oisf-devel] Source code technical question

Victor Julien victor at inliniac.net
Wed Jul 24 13:47:19 UTC 2013


On 07/24/2013 03:21 PM, Duarte Silva wrote:
> Hi all,
> 
> I was dwelling into Suricata source code and came across this:
> 
> #define DEBUG_ASSERT_FLOW_LOCKED(f) do {            \
>     if ((f) != NULL) {                              \
>         int r = SCMutexTrylock(&(f)->m);            \
>         if (r == 0) {                               \
>             BUG_ON(1);                              \
>         }                                           \
>     }                                               \
> } while(0)
> 
> Just wondering, whats the advantage of having this inside a do/while? Is it 
> because the compiler will optimize it out if not in a debug build?
> 

Answers can be found on stackoverflow:

http://stackoverflow.com/questions/923822/whats-the-use-of-do-while0-when-we-define-a-macro
http://stackoverflow.com/questions/154136/do-while-and-if-else-statements-in-c-c-macros
http://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for

-- 
---------------------------------------------
Victor Julien
http://www.inliniac.net/
PGP: http://www.inliniac.net/victorjulien.asc
---------------------------------------------




More information about the Oisf-devel mailing list