Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: forward references in typedefs Message-ID: <10605@smoke.BRL.MIL> Date: 25 Jul 89 18:10:36 GMT References: <55480@tut.cis.ohio-state.edu> <1989Jul20.152935.14872@utzoo.uucp> <24CB9E07.9547@marob.masa.com> <18729@mimsy.UUCP> <686@ftp.COM> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 14 In article <686@ftp.COM> wjr@ftp.UUCP (Bill Rust) writes: >The only way to tell if a jump table is better than compare and jump is to >see what the range of the switch variable is and how many values it >actually assumes. This is very difficult to do in a one pass compiler. I don't see that it's particularly hard to do. The compiler generates a preamble that branches to a postamble to be generated later (after the entire switch has been seen), and for each case as it is encountered the case value is stashed in a compiler internal table (only 257 labels need be accommodated) and an entry point label output followed by the case code then a jump to a second deferred label which will follow the postamble. The postamble can be a jump table, or a sequence of comparisons (hopefully ordered as a binary tree instead of linear), or any other algorithm the compiler decided was best for the particular set of case labels.