Labels as values?
Michael P. Gerlek
mikeg at c3.c3.lanl.gov
Mon Jul 9 03:03:56 AEST 1990
While modifying someone else's (<-disclaimer) goto-and-label-ridden
code, I declared a variable and mistyped it later on -- and my typo
happened to be the name of an existing label. Caused no end of
mysteries.
Simple case:
char *ptr;
label:
...
ptr = (char *)label;
...
This code is accepted by both by VAX UNIX and Sun C compilers, but not
by gcc (no, I don't have version numbers handy, sorry). I'm certainly
no expert, but I'm thinking gcc is right in complaining my use of
label in the assignment is invalid since label isn't declared as a
variable - if I do declare it, it works fine (even though the
identifier 'label' is used in two different contexts).
Neither K&R nor Harbison&Steele seem to have anything to say about
this. What does the Standard say? Is it legal to use a label as a
value-returning construct? And if so, of what type should the label
be considered to be?
[ M.P.Gerlek (mikeg at lanl.gov) ]
[ Los Alamos Nat'l Lab / Merrimack College ]
[ Disclaimer: Yes, Mom, I'll play nice. ]
More information about the Comp.lang.c
mailing list