1

I found following function in a device driver code.

static void module_exit(void)
{
        do { } while (0);
}

my question is why they used do { } while (0); inside this function. They can simply return from there instead of calling this do { } while (0);. Is there any special reason for having do { } while (0); here?

Chinna
  • 3,930
  • 4
  • 25
  • 55
  • 1
    It looks like "leftover junk". The (empty) loop will immediately terminate on the first while-condition check, if it isn't optimized away entirely. Now, if there was *actual* code in the loop (and perhaps outside), then it could use `break` or `continue` as a form of flow-control .. – user2864740 Feb 06 '14 at 06:26
  • look http://stackoverflow.com/questions/3766827/how-does-do-while0-work-in-macro – Jayesh Bhoi Feb 06 '14 at 07:16
  • An optimizing compiler might even optimize the whole loop away. – Jabberwocky Feb 06 '14 at 08:03

1 Answers1

0

There is no special reason to use do while, normally in a module_exit has clean up functions will un-register drivers. Do while will exit in your case. While(0) is like false case and will fall out of loop immediately .

gsujay
  • 41
  • 3