• Don't we all love those DoNothing functions? Well, so does most of the open source development community!!! Simply goto the C Source Search page, and search for the function name DoNothing, and find all those open source projects that have the famed function! The search engine does not index ALL open source projects, but it does index enough for you to go WTF?!?!? The site was slashdotted recently, so it might be slow.

  • lol... this post would be pretty useless without the link:


  • An example from everyones favorite cross platform media player VLC:

    1. static void DoNothing( aout_instance_t *p_aout )
    2. {
    3. return;
    4. }

  • Here's another one from Mozilla's Gecko engine SDK. This is listed under the Mac theming files.

    1. static pascal void
    2. DoNothing(const Rect *bounds, UInt32 eraseData, SInt16 depth, Boolean isColorDev)
    3. {
    4. // be gentle, erase nothing.
    5. }

  • I visited your link to the Mozilla example.  It looks like they're
    using the DoNothing so that another routine that expects a function
    pointer can operate properly.  I can only theorize that the
    holding routine doesn't or can't handle a NULL value for the function
    pointer.  shrug Doesn't make sense to me, but it must make sense
    to someone.  Right?  Right?

  • Most of the DoNothing functions in those projects are there because of cross platform stuff... Really not a WTF if you ask me, but it is funny considering the content of this site 😉

  • I've done some "donothing" functions.

    If you're calling a lot of functions through function pointers, and in most cases the pointer should not be NULL, it may make sense to declare a "do nothing" function as a target instead of adding a check for the NULL before every single call.

    So, for instance, if 99% of your calls are useful, and only 1% are NULL, it makes sense to take the cost of 1% of pointless empty function call than the 100% checks for NULLness.

  • I have in the past actually needed one once or twice to ensure proper timing...
    Those were of course the Assembly days, and the function would be given a parameter indicating for how long it should do nothing, then do exactly that 🙂

    Handy when you need to wait X clockcycles before you're allowed to push the next batch of data to a serial port for example.

  • I've seen plenty of do nothings in proprietary code.  The main use
    is to get rid of "Parameter was not used" warnings where the parameter
    was added to maintain style-  for example, a struct * (basicly a
    this) pointer on a module where multiple instances are not supported.

    The other is as previously described-  as a fake to a function pointer where you don't want the null check. 

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.