lkml.org 
[lkml]   [1999]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Structure vs purism ?
On Wed, 20 Jan 1999, Dave Jones. wrote:
> Just under 1000 goto's. Some of which are trivial. Goto's to one-liners,
> which are easily tidied. Other files are real snakes-nests. Following the
> trail of goto's as they double back on themselves is no fun for the brain,
> even less so for a CPU, as modern features such as branch prediction are
> misused.
The goto's are mostly used in "fast-path", where we want to avoid
jumping in non-error case. Look at a quick example:

--- no.c ---
main(void)
{
int i, j;
scanf("%d %d\n", &i, &j);

if (!i)
exit();
i++;
if (!j)
_exit();
j++;
}
--- end ---
--- no.dump ---
main():
080484a0 <main> pushl %ebp
080484a1 <main+0x1> movl %esp,%ebp
080484a3 <main+0x3> subl $0x8,%esp
080484a6 <main+0x6> leal 0xfffffff8(%ebp),%eax
080484a9 <main+0x9> pushl %eax
080484aa <main+0xa> leal 0xfffffffc(%ebp),%eax
080484ad <main+0xd> pushl %eax
080484ae <main+0xe> pushl $0x804852c
080484b3 <main+0x13> call 080483fc <_init+0x5c>
080484b8 <main+0x18> addl $0xc,%esp
080484bb <main+0x1b> movl 0xfffffffc(%ebp),%eax
080484be <main+0x1e> testl %eax,%eax
080484c0 <main+0x20> jne 080484c8 <main+0x28> ---------------
080484c2 <main+0x22> call 0804840c <_init+0x6c> |
080484c7 <main+0x27> nop |
080484c8 <main+0x28> incl %eax <--- jump ----
080484c9 <main+0x29> movl %eax,0xfffffffc(%ebp)
080484cc <main+0x2c> movl 0xfffffff8(%ebp),%eax
080484cf <main+0x2f> testl %eax,%eax
080484d1 <main+0x31> jne 080484d8 <main+0x38> ---------------
080484d3 <main+0x33> call 0804841c <_init+0x7c> |
080484d8 <main+0x38> incl %eax <--- jump ----
080484d9 <main+0x39> movl %eax,0xfffffff8(%ebp)
080484dc <main+0x3c> leave
080484dd <main+0x3d> ret
080484de <main+0x3e> nop
080484df <main+0x3f> nop
--- end ---
--- yes.c ---
main(void)
{
int i, j;
scanf("%d %d\n", &i, &j);

if (!i)
goto out;
i++;
if (!j)
goto out1;
j++;
out:
exit();
out1:
_exit();
}
--- end ---
--- yes.dump ---
main():
080484a0 <main> pushl %ebp
080484a1 <main+0x1> movl %esp,%ebp
080484a3 <main+0x3> subl $0x8,%esp
080484a6 <main+0x6> leal 0xfffffff8(%ebp),%eax
080484a9 <main+0x9> pushl %eax
080484aa <main+0xa> leal 0xfffffffc(%ebp),%eax
080484ad <main+0xd> pushl %eax
080484ae <main+0xe> pushl $0x804852c
080484b3 <main+0x13> call 080483fc <_init+0x5c>
080484b8 <main+0x18> addl $0xc,%esp
080484bb <main+0x1b> movl 0xfffffffc(%ebp),%eax
080484be <main+0x1e> testl %eax,%eax
080484c0 <main+0x20> je 080484d1 <main+0x31>
080484c2 <main+0x22> incl %eax
080484c3 <main+0x23> movl %eax,0xfffffffc(%ebp)
080484c6 <main+0x26> movl 0xfffffff8(%ebp),%eax
080484c9 <main+0x29> testl %eax,%eax
080484cb <main+0x2b> je 080484d8 <main+0x38>
080484cd <main+0x2d> incl %eax
080484ce <main+0x2e> movl %eax,0xfffffff8(%ebp)
080484d1 <main+0x31> call 0804840c <_init+0x6c>
080484d6 <main+0x36> movl %esi,%esi
080484d8 <main+0x38> call 0804841c <_init+0x7c>
080484dd <main+0x3d> leal 0x0(%esi),%esi
--- end ---
Kris
--
Krzysztof G. Baranowski - Linux System V Filesystem Maintainer
http://www.knm.org.pl/prezes/sysv.html <prezes@knm.org.pl>


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:49    [from the cache]
©2003-2011 Jasper Spaans