"possibly the nastiest piece of abuse of the C switch statement rules I know of"...

@best

"possibly the nastiest piece of abuse of the C switch statement rules I know of" hachyderm.io · 14 points · 4 comments · HN thread

TL;DR The article could not be read: the Mastodon page only returned a request to enable JavaScript. The post, by Simon Tatham (known for his puzzle collection and PuTTY), is titled as a very nasty abuse of C switch statement rules that exposed a compiler bug. The digest therefore relies on the title and the four comments.

  • Simon Tatham posted on Mastodon describing what he calls possibly the nastiest abuse of C switch statement rules he knows of.
  • According to a commenter quoting the post, the trick exposed a compiler bug.
  • One commenter notes that the technique shows switch cases behave like goto, able to jump into otherwise impossible places in the code.
  • Another commenter argues that the bug hunt was unnecessary and that the code is too clever to be understood by anyone without its context.
  • The page itself could not be loaded, so the actual code and details of the bug are not confirmed here.

Discussion The thread is small, with four comments. Most of it is about the author rather than the code: one commenter recognises Tatham from his puzzle packs and PuTTY, and the rest debate whether the switch trick is a clever insight or needlessly obscure code. The mood is light and mildly amused, with some pointed criticism of the code's cleverness.

  • Switch jumps reveal goto-like behaviour (some): One commenter points out that switch cases are essentially goto labels, so the trick jumps into positions that normal structured code cannot reach. They find the example a good illustration of that equivalence, and note the irony that the advice to avoid goto does not stop it.
  • Code too clever and unintuitive (some): A commenter argues that the post's cleverness exposed a compiler bug but was unnecessary, echoing the saying that clever code is hard for future readers. Another commenter agrees that the code is far too unintuitive for anyone who did not write it recently.
  • Admiration for the author's work (a few): A commenter says they were surprised to see the name, having played Tatham's puzzle packs for years and used PuTTY as their Windows client. The comment is appreciative rather than about the code.

#C #switchStatement #compilers #goto #programming