News for hackers. Stuff that matters.
Re:Coroutines in C (2000) by hectorhector on Thursday February 07, 2019 @01:49PM (#19107384)
What's the purpose of this code in the original decompressor? Assuming c is an uchar, aren't EOF and 0xFF equal?

  if (c == 0xFF) {
    len = getchar();
    c = getchar();
    while (len--)
    emit(c);
  }
Re:Coroutines in C (2000) by pm215 on Thursday February 07, 2019 @01:58PM (#19107480)
c should not be a char or unsigned char, because the return type of getchar() is "int". If you put it into a char-width variable then you lose the distinction between EOF (which is -1) and the byte 0xff. Getting the type of 'c' wrong is quite a common bug, because the API makes it an easy mistake to make. In this case, if you look down at the eventual transformed code in the "Evaluation" section you'll see that 'c' is indeed correctly declared with 'int' type.
Re:Coroutines in C (2000) by varjag on Thursday February 07, 2019 @02:00PM (#19107486)
getchar() returns an int to accommodate 257 different values: all byte chars + EOF (typically -1).

The code snippet itself is run length encoding with 0xff as an escape.

Re:Coroutines in C (2000) by tonyedgecombe on Thursday February 07, 2019 @01:52PM (#19107416)
Decompression, the first byte is the number of repeats and the second is the byte to repeat.
Re:Coroutines in C (2000) by hectorhector on Thursday February 07, 2019 @01:53PM (#19107425)
Ah, thanks!
Re:Coroutines in C (2000) by stevekemp on Thursday February 07, 2019 @02:40PM (#19107840)
Specifically this is known as "Run Length Encoding".