Can someone please tell me if it is acceptable to use same goto labels in different functions in the same C file?
To explain what I am facing:
function1()
{
...
goto label
...
label:
...
}
function2()
{
...
goto label;
...
label:
...
}
Now whats happening is that the code after the label is being used for cleanup of malloc'ed' data. And the whole thing is crashing in function2. I printed out the mem. locations which are being free and the same are being freed multiple times. Is this because of all the gotos? Is this valid use of the goto statement?
Labels are local, so you can use the same label in multiple functions.
The question about if you should use goto
is a different matter though, and one that is not easily answered. In short, don't use goto
. But as with everything (especially when it comes to programming) there are exceptions where goto
may be useful.