switch statements (was: forward references in typedefs)

John Cowan cowan at marob.masa.com
Thu Jul 27 03:00:57 AEST 1989


In article <18729 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>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.

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 at 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.



More information about the Comp.lang.c mailing list