Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: forward references in typedefs Message-ID: <18729@mimsy.UUCP> Date: 25 Jul 89 06:28:58 GMT References: <55480@tut.cis.ohio-state.edu> <1989Jul20.152935.14872@utzoo.uucp> <24CB9E07.9547@marob.masa.com> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 54 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. >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, code at each of the labels, a branch at the bottom, and then generate the code that actually implements the switch. E.g., given switch (foo) { case 1: case1(); break; case 2: case2(); break; case 3: case3(); break; case 999: case999(); break; } onward(); one generates code of the form: jump L1 L3: call case1_ jump L2 L4: call case2_ jump L2 L5: call case3_ jump L2 L6: call case999_ jump L2 L1: move foo,r0 compare r0,#3 jeq L5 jgt L7 compare r0,#1 jeq L3 jgt L4 # here is the clever part jump L2 L7: compare r0,#999 jeq L6 L2: call onward_ This sort of code is exactly what one gets from a one-pass compiler, except that they tend not to have a clever part. :-) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris