X3J11: Why no labelled loops?

herndon at umn-cs.UUCP herndon at umn-cs.UUCP
Mon Mar 2 10:30:00 AEST 1987

>In article <388 at cognos.UUCP> brianc at cognos.UUCP (Brian Campbell) writes:
>   Why are labelled loops not supported in ANSI C?
>>/* Written  7:17 pm  Feb 87, 19783 by mntgfx!franka in umn-cs:comp.lang.c */
>>Now for my pet peeve.  Why can't you take the address of a label? ...
>>   label   *jump_table[] = { &exe_seg_0, &exe_seg_1, ... };
>>... justifications for this ...
>...... In fact, I wonder why this idea has not been implemented before...
>Frank Adrian
>Mentor Graphics, Inc.

  In fact, this *used* to be legal, and has been done.  In days of
old (when knights were *ahem*) labels had type (int *).  Thus a
programmer could quite easily load an array full of label values
and happily goto <expr>.
  It peeves me greatly too, since I would like to maintain my own
call stack for a threaded interpreter; allowing the C compiler
to maintain it will cost me >>10 times the space.  (I can code the
info needed to save and restore my environments in less than 2 bytes;
the stacks may grow very deep: ~= 100K procedure calls.)
Since I can't use arrays of labels, I either:
  1) Have to use a machine dependent hack for jumping to the code
  2) Have to maintain the stack myself, iteratively calling procedures
     which do what I want, while passing add'l call/return info
     with the calls and returns, costing me the time of the
     procedure call and return, and forcing me to generate useless
     prologue/epilogue code for each procedure.
  The former prohibits me from uniformly mixing dynamically generated
and statically compiled code.  The latter uglifies code generation
and costs time (procedure overhead) and space (code) performance.

More information about the Comp.lang.c mailing list