Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
kvsm6865yInteresting, do you have an example of not misusing it?
@kvsm I second @slinavipuz. Think of a function that mallocs memory several times. If the second malloc fails you should free the first but not the others.
If this third fails you should free the first two but not the third.
That's how it's done in the Linux kernel.
a = alloc
if a failed goto a_fail
b = alloc
if b failed goto b_fail
c = alloc
if c failed goto c_fail
@slinavipuz Which is a good thing. You have to scare students with gotos, because it's always the last solution. Coding the above if if/else would be an abomination if you have more than 2 allocs.
Maybe there should be a license to goto. Only allowed with 5 years pro experience, or something...