[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Are Goto's in the Linux Kernel necessarily bad?



> It depends on why they're being used.  In the kernel, they are being used 
> for error handling, and pretty much only error handling in complex 
> situations.
> 
> Any other use of a goto usually means bad code or intentionally 
> obfuscated.

Not true. They are prefectly suited to state machine execution and
jump tables (such as interrupt vectors). You really only need to use
gotos when you're close to the "metal". Which is where the kernel is.
The closer you are to the assembly and wiring, a "goto" is merely an integral
part of branching logic. Since in modern computers, instructions are executing
sequentially, any form of "If this, then execute A else execute B" means that
someone (A or B) necessarily *cannot* possibly be the next sequential set
of instructions to be executed. So, if the branch is taken to execute the
"other" code (non-sequential), the only mechanism a CPU has to fetch that
set of instructions is necessarily a "goto" instruction.

But, back to the kernel. It has to run on *lots* of hardware. So, it has 
constraints being placed on it that do not apply to general user application 
programming, which is what the people who gave lectures about "Goto considered
harmful" and such in the early 80's of Computer Science.

You should read a more recent book, Jonathan... :=)

Mike808/

---------------------------------------------
http://www.valuenet.net



-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.