Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!rochester!pt.cs.cmu.edu!ius2.cs.cmu.edu!Eddie.Wyatt From: Eddie.Wyatt@ius2.cs.cmu.edu.UUCP Newsgroups: comp.lang.c Subject: Re: jumptables Message-ID: <1063@ius2.cs.cmu.edu> Date: Wed, 11-Mar-87 15:15:03 EST Article-I.D.: ius2.1063 Posted: Wed Mar 11 15:15:03 1987 Date-Received: Fri, 13-Mar-87 00:19:46 EST References: <9929@sri-spam.istc.sri.com> <649@vu-vlsi.UUCP> Sender: edw@ius2.cs.cmu.edu Organization: Carnegie-Mellon University, CS/RI Lines: 97 To follow is the assemble language generated by a C compiler running on a Vax 780 (Unix os of course) for a case statement. LL0: .data .text .align 1 .globl _main _main: .word L12 jbr L14 L15: movl -4(fp),r0 jbr L17 L18: movl -12(fp),-8(fp) jbr L16 L19: movl -16(fp),-20(fp) jbr L16 L20: movl -20(fp),-16(fp) jbr L16 L21: movl -8(fp),-16(fp) jbr L16 L22: movl -8(fp),-24(fp) jbr L16 L23: movl -24(fp),-16(fp) jbr L16 L17: casel r0,$0,$5 L24: .word L18-L24 .word L19-L24 .word L20-L24 .word L21-L24 .word L22-L24 .word L23-L24 L25: L16: ret .set L12,0x0 L14: subl2 $24,sp jbr L15 .data Original code main() { int c; int h, k, j, i, m; switch (c) { case 0: h = k; break; case 1: i = j; break; case 2: j = i; break; case 3: j = h; break; case 4: m = h; break; case 5: j = m; break; } } Note that the vax has a special case instruction. The answer to your question of why you can't have jump tables is that it is up to the C compiler to make such optimizations that may be machine depended. May I also ask have you checked the code that your C compiler has generated to make sure it is not generating direct threaded code for case statements? As I have been told, the C compiler for the Suns does. Eddie Wyatt Research Programming (CMU) edw@ius1.cs.cmu.edu