-3

So my problem looks like, I have two procedures and they call each other but this can provide overflow. How to JUMP to procedure - like asm jmp not call? I don't want to use labels because I can't use GoTo between two different procedures. And I don't want the code which follows calling to a procedure to be executed. BTW, I use FPC.

unit sample;
interface

procedure procone;
procedure proctwo;

implementation

procedure procone;
begin
writeln('Something');
proctwo;
writeln('After proctwo'); //don't execute this!
end;

procedure proctwo;
begin
writeln('Something else');
procone;
writeln('After one still in two'); //don't execute this either
end;

end.
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
pfoof
  • 195
  • 1
  • 13
  • 1
    Why do your procedures contain code you don't want to execute? – Wooble Jul 16 '12 at 17:15
  • That's extremely complicated. As I said I don't want to CALL a procedure I want to JUMP to a procedure with leaving the following code not executed. – pfoof Jul 16 '12 at 17:22
  • 1
    A) Rewrite your code so there's no circular references. B) Remove the code you don't want to execute. C) If A or B doesn't solve your problem, post a **real** example of the situation you're experiencing and a better description of the problem, because this one is silly. – Ken White Jul 16 '12 at 19:13

1 Answers1

1

You'll have to use function parameter to indicate recursion so the function will know it's being called by related function. e.g.:

unit sample;

interface

procedure procone;
procedure proctwo;

implementation

procedure procone(const infunction : boolean);
begin
  writeln('Something');
  if infunction then exit;
  proctwo(true);
  writeln('After proctwo'); //don't execute this!
end;

procedure proctwo(const infunction : boolean);
begin
  writeln('Something else');
  if infunction then exit;
  procone(true);
  writeln('After one still in two'); //don't execute this either
end;

procedure usagesample;
begin
  writeln('usage sample');
  writeln;
  writeln('running procone');
  procone(false);
  writeln;
  writeln('running proctwo');
  proctwo(false);
end;

end.

When usagesample is called, it should produces this:

usage sample

running procone
Something
Something else
After proctwo

running proctwo
Something else
Something
After one still in two
Jay
  • 4,627
  • 1
  • 21
  • 30