Thank you very much !!! On 8/7/05, Thomas Petazzoni <thomas.petazzoni@xxxxxxxx> wrote: > Hi, > > Bob Smith a écrit : > > > Why is that ? I googled up reasons like minimizing return points, > > but is that it ? > > Most of the time, 'goto' is used to minimize code duplication in error > handling. > > Without 'goto': > > int myfunc (void) > { > ret = dosomething1(); > if (ret < 0) > return ret; > > ret = dosomething2(); > if (ret < 0) > { > undosomething1(); > return ret; > } > > ret = dosomething3(); > if (ret < 0) > { > undosomething2(); > undosomething1(); > return ret; > } > > ret = dosomething4(); > if (ret < 0) > { > undosomething3(); > undosomething2(); > undosomething1(); > return ret; > } > return 0; > } > > With 'goto': > > int myfunc(void) > { > ret = dosomething1() > if (ret < 0) > goto ret_dosomething1; > > ret = dosomething2() > if (ret < 0) > goto ret_dosomething2; > > ret = dosomething3() > if (ret < 0) > goto ret_dosomething3; > > ret = dosomething4() > if (ret < 0) > goto ret_dosomething4; > > ret_dosomething4: > undosomething3(); > ret_dosomething3: > undosomething2(); > ret_dosomething2: > undosomething1(); > ret_dosomething1: > return ret; > } > > Sincerly, > > Thomas > -- > PETAZZONI Thomas - thomas.petazzoni@xxxxxxxx > http://thomas.enix.org - Jabber: thomas.petazzoni@xxxxxxxxx > KOS: http://kos.enix.org/ - SOS: http://sos.enix.org > Fingerprint : 0BE1 4CF3 CEA4 AC9D CC6E 1624 F653 CB30 98D3 F7A7 > > > > -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/