27

I used a GOTO statement today, and I am proud of it.

Comments
  • 8
    Good. Now go get flogged a hundred times, as people do.
  • 1
    It was a cli script that only I will ever run, in a retry/abort situation after a network request...
  • 3
    I still miss goto via array index in the C standard. They made that useless VLA shit mandatory in C99, only to pull it back to optional in C11, but computed goto is still only a GCC/Clang extension. Meh.
  • 3
    There's another way for a Y/N situation in a bat file?
  • 2
    You Moran
  • 2
    @C0D4 There is a way. use python, like a vertebrate species. Unless you use windows. you are on your own there...
  • 0
    welcome to the Real darkside 😀
  • 0
    Is the Linux kernel still using lots of goto statements? Haven't followed in a while
  • 4
    You know deep inside what you did. How long can you take it ? The guilt ?
  • 4
    You will GOTO hell.
  • 3
    You monster.
  • 1
    @Fast-Nop elaborate about that C-thing
  • 3
    @irene You can have labels inside a function, put the label addresses into a local const array, and then make a goto via the index of that array, i.e. a jump table.

    That's super cool for dispatchers or interpreters. IIRC that trick sped up Python by 20%. Or if you have a lot of very small lists for sorting, then you can use sorting networks and jump to the right one via the list length as jump table index.

    Sometimes, the compiler will make a jump table out of a switch/case, but that isn't guaranteed and can break easily.

    Of course, you can also instead make an array with function pointers and call the "right" function depending on the index, but that leaves the function call overhead.
  • 1
    @Fast-Nop O.o sounds cool
  • 2
    @irene @Fast-Nop Yeah, hate to burst your bubble, but that no longer really speeds up interpreters. GCC can perfectly recognize a dispatch switch-statement now, and computed goto's usually slightly slow it down (example: https://badootech.badoo.com/when-pi...).
  • 0
    @AnsiNotAscii That depends strongly on the individual case. As I said, it can break easily, depending on the range covered within the cases.
Your Job Suck?
Get a Better Job
Add Comment