Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!apple!oliveb!pyramid!prls!philabs!phri!marob!cowan From: cowan@marob.masa.com (John Cowan) Newsgroups: comp.lang.c Subject: switch statements (was: forward references in typedefs) Message-ID: <24CDEE4B.4647@marob.masa.com> Date: 26 Jul 89 17:00:57 GMT References: <55480@tut.cis.ohio-state.edu> <1989Jul20.152935.14872@utzoo.uucp> <24CB9E07.9547@marob.masa.com> <18729@mimsy.UUCP> Reply-To: cowan@marob.masa.com (John Cowan) Organization: ESCC, New York City Lines: 36 In article <18729@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >In article <24CB9E07.9547@marob.masa.com> cowan@marob.masa.com (John Cowan) >writes: >>... As someone (Chris Torek?) said earlier in this group, "all 'struct' >>pointers must 'smell' the same." If this behavior is not guaranteed, >>forward references to structs would be unimplementable in one pass. > >It was Doug Gwyn, but this is otherwise correct. Sorry about that. I, like Usenet, tend to lose my memory every six months. :-) >>Ufcawss, if you talk to the people who wrote VMS C, they'll tell you that >>all one-pass implementations of C are unacceptable! (This has something to >>do with generating good code for the 'switch' statement.) > >They are both right and wrong. One-pass code generation means there >are few opportunities for optimsiation; but generating good switches >is easy. Simply emit a branch at the top of the switch... I looked up the complaint, and they don't like this unconditional branch. It involves jumping around the whole of a potentially large switch statement, and then back up to somewhere within the code. In a paging architecture with small pages (like VMS: 512 bytes/page), this may involve an unnecessary page fault just to get to the jump table. A two-pass compiler allows putting the jump table at the top. The VMS compiler actually emits most code on the first pass, watching in the mean time for switch statements and a few other constructs, and then runs a second pass to fix these constructs only if they were detected. He who eschews 'switch' wins fast compiles under VMS. -- Internet/Smail: cowan@marob.masa.com Dumb: uunet!hombre!marob!cowan Fidonet: JOHN COWAN of 1:107/711 Magpie: JOHN COWAN, (212) 420-0527 Charles li reis, nostre emperesdre magnes Set anz toz pleins at estet in Espagne.