Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

COND

Name: Anonymous 2012-09-05 10:08

Why doesn't C have the sugar syntax for COND yet?

Name: Anonymous 2012-09-05 15:48

That's some dirty code, but it fucking works!

int cond(int count, ...)
{
  assert(count > 0);

  va_list ap;
  va_start(ap, count);

  int predicate = 0, result;
  while (count-- || !predicate)
  {
    predicate = va_arg(ap, int);
    result    = va_arg(ap, int);
  }

  va_end(ap);
  return result;
}

int y = cond(3,
             x < 10,  5,
             x == 10, 6,
             x > 10,  7);

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List