Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!bagate!cbmvax!cbmehq!cbmdeo!jsmami!jsmoller From: jsmoller@jsmami.UUCP (Jesper Steen Moller) Newsgroups: comp.sys.amiga.programmer Subject: Re: Lemmings - a tutorial Part V (last) Message-ID: <18f2e1f5.ARN12a7@jsmami.UUCP> Date: 7 Apr 91 13:38:01 GMT References: <1991Mar31.003933.1483@mintaka.lcs.mit.edu> <1991Apr1.020748.26863@mintaka.lcs.mit.edu> <18ee3f47.ARN125e@jsmami.UUCP> <19 Reply-To: cbmehq!cbmdeo!jsmami!jsmoller (Jesper S. Moller) Followup-To: comp.sys.amiga.programmer Organization: Danish SofTech Lines: 82 In article <1991Apr5.234958.23678@starnet.uucp>, Stephan Schaem writes: > Come one how many people here dont use jump table instead of multi cmp? I will not let this point go down the drain: A typical example where multi cmp's are the best: switch (gadCode) { case 1: break; case 37: break; case 100: break; case 1000: break; } This is an extreme example, but not at all unlikely. A multi-cmp is the likely here, right? Ok, now consider: switch (gadCode) { case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; case 8: break; } A jump table would be preferred, right? The point is - the C compiler knows what's the best - so does the assembler programmer. If one value is changed, the C compiler will redo the work. So will the assembler programmer. During development, values change oftenly... This reminds me of: ---- #define CONSTANT 37 number *= CONSTANT; ----- verses: ------ CONSTANT EQU 37 mulu #CONSTANT,d0 ------ Aha, now change CONSTANT to 16. The C-compiler catches this, while the assembler programmer has to know all about where CONSTANT is placed to optimize this case. So for large projects, C must be the least bothering of the two... > The C compiler need to ANDERSTAND what you are doing for it to do > 'perfect' compilation. As a switch sentence is limited to constants, It needn't understand that much. It can compute which solution is the most efficient. And the human user doesn't have to recode the entire switch construction when one single value changes. As the equivalent assembler coder would have. > Soembody wrote the C compiler anyway. Yes, typically a person with a thorogh knowledge of the achitecture from assembler up to higher structured languages than C. Someone with the right theoretical background. Someone like Matt. - Jesper -- __ Jesper Steen Moller /// VOICE: +45 31 62 46 45 Maglemosevej 52 __ /// USENET: cbmehq!cbmdeo!jsmoller DK-2920 Charl \\\/// FIDONET: 2:231/84.45 Denmark \XX/