[Oisf-devel] Source code technical question

Duarte Silva duarte.silva at serializing.me
Wed Jul 24 14:10:46 UTC 2013


On Wednesday 24 July 2013 15:47:19 Victor Julien wrote:
> 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-i
> n-c-c-macros
> http://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for

Thanks Victor, I should have googled it :D it never crossed my mind it had 
anything to do with semi-colons and code blocks. I allways use brackets even 
for one instruction if's. Hence, when the macro required a code block I just 
used brackets (it was the Microsoft compiler though, might be different from 
GCC).

Thanks,
Duarte



More information about the Oisf-devel mailing list