Reputation: 43
I have a piece of code that, very simplified, looks like this
program helloworld;
a:integer;
procedure alpha;
begin
writeln('This is procedure alpha');
beta;
end;
procedure beta;
begin
writeln('This is procedure beta');
alpha;
end;
begin
readln(a);
if a=1 then alpha;
if a=2 then beta;
end.
That is of course an example, but you get what am I trying to say. I know where the error is - I'm trying to use a procedure, that has not been defined yet -, but what I'm trying to figure out is how to make pascal "ignore" it until it really becomes a problem (here it's not a problem, because procedure beta is defined later)?
TLDR; How to use procedure, that has not yet been defined?
Upvotes: 4
Views: 921
Reputation: 14185
Pascal only knows about what has already been defined, so you need a forward
declaration before any of the procedures :
procedure beta; forward;
procedure alpha;
begin
writeln('This is procedure alpha');
beta;
end;
procedure beta;
begin
writeln('This is procedure beta');
alpha;
end;
However, note that your code will create an infinite loop of calls that will generate either an stack overflow (quite appropriately) or an infinite loop, depending on your compiler.
Upvotes: 4