Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
It was a cli script that only I will ever run, in a retry/abort situation after a network request...
-
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.
-
@C0D4 There is a way. use python, like a vertebrate species. Unless you use windows. you are on your own there...
-
@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. -
@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...).
-
@AnsiNotAscii That depends strongly on the individual case. As I said, it can break easily, depending on the range covered within the cases.
-
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. -
@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.
Related Rants
I used a GOTO statement today, and I am proud of it.
rant
goto