[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Are Goto's in the Linux Kernel necessarily bad?
Huh? Well, I didn't think a big answer was wanted, so I used the word
"usually". I like generalities.
Speaking of kernels and hardware, I spent four years hacking on embedded
systems drivers and applications for VxWorks & and a proprietary kernel.
I've also done things like porting a kernel (something like 3000 C & 68k
assy. files worth) from a 68k processor board to run as a process on
Solaris. Helped with about 10k lines of DSP assembly too-- dealing with 2
memory buses was pretty novel (don't ask me which chip). So I think I'm
qualified to open my mouth here.
Mike
On Sat, 15 Feb 2003 mike808@users.sourceforge.net wrote:
> > 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.
>
-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.