tags:

views:

135

answers:

1

I just found the existence of qt_noop() define in the qglobal.h as:

inline void qt_noop() {}

What's the point of it?

+4  A: 

I know it's used internally in some macros that should do something only for debug builds, for example:

#  ifndef QT_NO_DEBUG
#    define Q_ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop())
#  else
#    define Q_ASSERT(cond) qt_noop()
#  endif
#endif
chalup
So its sole purpose is to use the ternary operator (why not a single if?) since it could be omitted in the 2nd define?
gregseth
It can't be omitted in 2nd define. The Q_ASSERT macro is usually used like normal function call, i.e. `Q_ASSERT(xxx == yyy);`. So the macro must expand to code that can be followed with semicolon without any errors/warnings. As for the "single if", there are some issues with macros containing if when they are used inside other if statements without braces (see http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.4), so ternary operator might be a better idea here.
chalup
Accepted more for the comment and the link than the answer... anyway, thanks! :)
gregseth