[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: why goto ?
Goto is mainly used in functions where having multiple return points is not
possible.What I mean that u simply cannot afford to have 2 return statements
in the same function.If the function needs to dom some cleanup before it
exits -for eg,to release a resource it is holding -in the best cas it will
contain duplicated code.
U will find when u handle exceptions in C.
Let's say u have a piece f code
lock();//this will prevent any body from using a particular rsource .
Now consider the above program,The macros
excepA(status) and excepB(status) are exception handler's.Now when on
function A suppose it returns an exception.Now EXCEPA(status) should write
error code to some file and then execute the statement
It cannot just return to the parent function without giving back all the
resources .If it had
done like that then that resource which funA used would never be used
function must have a single exit point.For more info read the C/C++ user's
Feb 2001 edition.
----- Original Message -----
From: Anurag Shekhar <anurag@xxxxxxxxxxx>
Sent: Friday, March 09, 2001 12:26 PM
Subject: [LIP] why goto ?
> i was going through the kernel modules and saw lots of goto (in fact
> this is the only place i have seen goto in any c code) And Alessandro
> Rubini (Linux Device Driver) also recommends using goto for error
> handling in kernel modules. Is there any specific advantage of using it
> Find out more about this and other Linux India
> mailing lists at http://lists.linux-india.org/