So, assuming you have a reason for using a goto... just to avoid the inevitable arguments about why they should/shouldn't be used.
What happens when you declare a variable mid function, say a pointer to some memory that has to be free'd, and the flow control jumps past the variable altogether?
int foo(char* bar)
{
if (NULL == bar)
{
printf("ERR1\n");
goto out;
}
char* late = malloc(10 * (*bar));
if (NULL == late)
{
printf("ERR2\n");
goto out;
}
// More logic here
if (1)
{
printf("ERR3\n");
goto out;
}
// etc
out:
free(late);
return 0;
}
There are cases where in 'out:', you definitely want to free the memory allocated to variable 'late'(eg it fell through or came from 'ERR3'). There are also cases early in the function where late hasn't even been created yet and you jump past them.
Normally, when you declare a local variable like this, in assembly, there are some stack operations to move the stack pointer to have space to hold the new variable. I'd expect goto to act like an unconditional branch operation to a label. At the end of the function, all the locals gets left on the stack as the stack pointer is adjusted so control can return to the caller.
So, what happens with the 'late' variable when we hit 'ERR1'? Is space for it ever created on the stack? How does the 'free' call work just after the 'out' label?