28

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

Comments
  • 6
    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...
  • 2
    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.
  • 4
    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...
  • 6
    You will GOTO hell.
  • 4
    You monster.
  • 2
    @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
    @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.
  • 0
    I did the same in my Data Structures and Algo project. It was a polyhedron specification, for which I made a simple editor out of my test program.
    Setting up those menus is not what I'm eval'd about, so I don't care.
  • 1
    every time someone uses GOTO in their code a kitten dies
  • 2
    @jespersh it's because they know what they're doing. ^^

    @darksideofyay Yesterday I used GOTO two times in my code - for error handling with resource deallocation.

    My preferred idiom for that one goes like this because there's only one code path for deallocation. Easy to maintain and test.
Add Comment