label used before containing beinding

Frank Heckenbach ih8mj at
Mon Feb 2 15:29:32 CET 2004

Nick Ioffe wrote:

> I've encountered the message in the subject trying to compile
> the following:
> program x(input, output);
> label
> 	x_label;
> var
> 	z:integer;
> 	w:string;
> function f:string
> begin
> 	f:='f';
> end;
> begin
> 	if z = 1
> 	then
> 	begin
> 		writeln('to x_label');
> 		goto x_label;
> 	end;
> 	w:= 'z:'+f;
> x_label:;
> end.
> Compilation fails and I get:
> x.pas:3: label 'x_label' used before containing binding contour.
> If I surround w:= 'z:'+f; with 'begin/end' then everything compiles.
> also if summation is not on string everything compiles.
> I use "gpc version 20030507, based on gcc-3.2.1"
> I've found in the archive message #2535 descring the same problem.
> However the message seems to be unanswered, at least the answer 
> was not on the archive....

No answer, but a direct follow-up by the poster (without references,
so not listed as a reply in the archive, but see "Next mail"):

: Sorry for this message. I see I was already in the known bug list.
: Any takers for this error?

Unfortunately, this hasn't changed since then. This is one of the
more difficult bugs to fix.

The recommended work-around (in this case not meant negatively :-),
then as well as now, is to avoid using `goto' which is always
possible -- sometimes at the cost of a Boolean variable, often (as
in the example above, of course) even without one.

(BTW, even when having to use an extra variable, the resulting code
may be better. The variable can sometimes be optimized away, and the
compiler has better information about the control flow. Also, I'm
not sure, but the code generator may not be particularly tuned for
`goto' since it's generally not recommended.)


Frank Heckenbach, frank at,, 7977168E
GPC To-Do list, latest features, fixed bugs:
GPC download signing key: 51FF C1F0 1A77 C6C2 4482  4DDC 117A 9773 7F88 1707

More information about the Gpc mailing list