1

Inside boost/asio/coroutine.hpp there is case statement inside the definition of the macro yield which seems to be inaccessible:

  switch (_coro_value ? 0 : 1) \
    for (;;) \
      case -1: if (_coro_value) \
        goto terminate_coroutine; \
      else for (;;) \
        case 1: if (_coro_value) \
          goto bail_out_of_coroutine; \
        else case 0:

What is the purpose of case -1 since the switched value can only be either 0 or 1?

Oliv
  • 17,610
  • 1
  • 29
  • 72
  • 4
    Probably "no point/purpose".. my guess would be "the remnants of a "rock star" programmer who didn't know what the f he was doing".. either that or it's too clever for its own good. – Jesper Juhl Jun 04 '17 at 14:43
  • @JesperJuhl This is exactly what I doubt... – Oliv Jun 04 '17 at 14:45
  • why would you "doubt" it? To "doubt" something means to disbelieve it or not think it is correct.. – Jesper Juhl Jun 04 '17 at 14:46
  • `_coro_value ? 0 : 1` can be simplified to just `!_coro_value` – phuclv Jun 04 '17 at 14:47
  • @JesperJuhl I had answered before you edit your comment! Your first comment satisfies me now. – Oliv Jun 04 '17 at 14:48
  • 5
    You'll first have to make sense of the for(;;) sprinkled amongst the case statements. This is Duff's Device at work. You'll risk permanent brain damage, some odds the author did as well. I hope he's okay. – Hans Passant Jun 04 '17 at 15:13
  • Note that this is a *macro emulation of stackless coroutines*. It's "too clever for its own good" by definition. – milleniumbug Jun 04 '17 at 16:00

0 Answers0