Using &LABEL
bet at ecsvax.UUCP
bet at ecsvax.UUCP
Sat Sep 1 05:00:12 AEST 1984
This brings up my only *major* complaint with C -- the weakness of its
handling of labels. The question
>> Finally, is &LABEL an officially sanctioned K&R construct? I don't
>> have my copy with me so I can't look it up right now...
is pretty easy (I think): From the C Reference manual, in the back of
K&R, section 9.12:
... The only use of a label is as a target of a goto. ...
(You can take my word that this isn't an unreasonably out-of-context
quote). Many compilers, however, as an accident of implementation, give
the address in the code space when you use &label, allow you to assign
that to a variable of suitable size (int often works) and branch to
it. HOWEVER, this is flagrantly illegal and non-portable. The
definition of C prohibits it. So here goes my desired extention to C:
Make 'label' be a data type. Consider "<identifier> :" to be a
constant, allow label variables to be created, and in particular arrays
of labels. Voila: jump tables! Many (most) uses of goto <label> might
be unstructured, or even UGLY. However, one particular construct occurs
reasonably often in a kind of programming C is good at: implementing
compilers and suchlike text processors. This construct is the finite
state automaton. What you really want to implement one efficiently is a
label array, for "goto array[input]" to be a state transition.
It seems to me that this treatment of "label" wouldn't conflict with the
existing definition of C, and in fact would formally bless a "feature"
that some compilers already have. I am grateful, at least, that the
philosophy in designing a C compiler is to make it do everything that C
requires, but not necessarily to prohibit everything C prohibits. LONG
LIVE LINT!!!
Bennett Todd
...{decvax,ihnp4,akgua}!mcnc!ecsvax!bet
More information about the Comp.lang.c
mailing list