News for hackers. Stuff that matters.
Re:My Favourite Diff by Someone on Sunday April 05, 2020 @07:12PM (#22789516)
If that’s the most perverse you’ve seen, I guess you haven’t seen Duff’s device, which mixes it with a do…while loop (code copied from http://www.catb.org/~esr/jargon/html/D/Duffs-device.html):

   register n = (count + 7) / 8;      /* count > 0 assumed */

   switch (count % 8)
   {
   case 0:        do {  *to = *from++;
   case 7:              *to = *from++;
   case 6:              *to = *from++;
   case 5:              *to = *from++;
   case 4:              *to = *from++;
   case 3:              *to = *from++;
   case 2:              *to = *from++;
   case 1:              *to = *from++;
                      } while (--n > 0);
   }
Re:My Favourite Diff by tzs on Sunday April 05, 2020 @10:09PM (#22790348)
I have no idea if this still works in modern C, but here's something kind of similar I've seen used in C circa 1986:

  switch (foo)
  {
    case 1:
      ...code just for case 1...
      if (0)
      {
    case 2:
        ...code just for case 2...
      }
      ...code for both case 1 and case 2...
      break;
    case 3:
      ...

  }
used when two cases have a common tail, and you have sufficient space constraints that you do not want to duplicate the common tail code, and you have sufficient time constraints (and maybe space constraints on the stack) that you don't want to put the common tail code in a subroutine and call it from both cases.
Re:My Favourite Diff by fisherjeff on Sunday April 05, 2020 @10:47PM (#22790535)
Oh my god. I’ve wondered about a way to do this but... this is just devious.
Re:My Favourite Diff by X-Istence on Sunday April 05, 2020 @10:48PM (#22790546)
This is goto with slightly more code ;-)
Re:My Favourite Diff by aasasd on Monday April 06, 2020 @07:56AM (#22792899)
That's not perversity, that's suicide by art.