Difference between goto and function calls
-
Hi all, I'll try to explain my question as much as quickly. Actually its not a question, but a clarification I am looking for. Say I have a two code blocks which is doing two different things. I can implement those two blocks in two functions and call as I need from a third function. Or else, I can implement those two blocks in the third function and used goto jump between blocks. So what is the difference between two? Thanks for all the comments in advance.
If you've never failed... You've never lived...
-
Hi all, I'll try to explain my question as much as quickly. Actually its not a question, but a clarification I am looking for. Say I have a two code blocks which is doing two different things. I can implement those two blocks in two functions and call as I need from a third function. Or else, I can implement those two blocks in the third function and used goto jump between blocks. So what is the difference between two? Thanks for all the comments in advance.
If you've never failed... You've never lived...
// So what is the difference between two? I would say - stack - accountability for the heap (de-)allocations - perfomance - re-usage of the functions - readability What thesis does stay misty for you ? :)
They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)
-
Hi all, I'll try to explain my question as much as quickly. Actually its not a question, but a clarification I am looking for. Say I have a two code blocks which is doing two different things. I can implement those two blocks in two functions and call as I need from a third function. Or else, I can implement those two blocks in the third function and used goto jump between blocks. So what is the difference between two? Thanks for all the comments in advance.
If you've never failed... You've never lived...
A goto wont add stuff to the stack like a function call will. But the problem is that the code that you goto has to get back somehow, which means embedding a label in your code, which means you goto code would be better just put in your calling code. So really, you should use a func, it will be easier. Gotos are useful for exiting funcs in error conditions. (Often replaced by a do{}while(0) these days).
============================== Nothing to say.
-
Hi all, I'll try to explain my question as much as quickly. Actually its not a question, but a clarification I am looking for. Say I have a two code blocks which is doing two different things. I can implement those two blocks in two functions and call as I need from a third function. Or else, I can implement those two blocks in the third function and used goto jump between blocks. So what is the difference between two? Thanks for all the comments in advance.
If you've never failed... You've never lived...
People will hate you if you use
goto
, it makes the code more difficult to test, debug and maintain; stick with functions. -
People will hate you if you use
goto
, it makes the code more difficult to test, debug and maintain; stick with functions.This is pure dogma. Any code can be crap and hard to maintain and goto when used judiciously is perfectly OK. For example:
myfunc()
{
do{
if(!somefunc())
continue;
if(!someotherfunc())
continue;}while(0);
}Is heavy when compared to:
myfunc()
{
if(!somefunc())
goto end;
if(!someotherfunc())
goto end;end:
}============================== Nothing to say.
-
This is pure dogma. Any code can be crap and hard to maintain and goto when used judiciously is perfectly OK. For example:
myfunc()
{
do{
if(!somefunc())
continue;
if(!someotherfunc())
continue;}while(0);
}Is heavy when compared to:
myfunc()
{
if(!somefunc())
goto end;
if(!someotherfunc())
goto end;end:
}============================== Nothing to say.
Erudite_Eric wrote:
This is pure dogma.
Not at all. And what's wrong with:
myfunc()
{
if(somefunc() &&
someotherfunc())
{
// do stuff
}
}