7

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

inline void qt_noop() {}

What's the point of it?

gregseth
  • 12,952
  • 15
  • 63
  • 96

1 Answers1

8

The "noop" name is short for "no operation", meaning it is a place-holder function that does nothing.

You may also know NOP, which exists in assembly-language.

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
Top-Master
  • 7,611
  • 5
  • 39
  • 71
chalup
  • 8,358
  • 3
  • 33
  • 38
  • 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 May 19 '10 at 12:51
  • 4
    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 May 19 '10 at 14:30
  • Accepted more for the comment and the link than the answer... anyway, thanks! :) – gregseth May 20 '10 at 20:44