forward references in typedefs
Chris Torek
chris at mimsy.UUCP
Tue Jul 25 16:28:58 AEST 1989
In article <24CB9E07.9547 at marob.masa.com> cowan at 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 at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list