Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem in Pascal

1 view
Skip to first unread message

Mike Kingzett

unread,
May 3, 1993, 2:40:50 PM5/3/93
to
I am stuck in a situation where I have three procedures which call each other.
However, there is no was to arrange them so that all are defined when called
thanks to Pascal's Top-Bottom design. Is there a way I can force a procedure
to be recognized by a procedure preceeding it??

I don't read comp.lang.pascal often, so could you respond by email?? Thanks.


James Paul Henley

unread,
May 4, 1993, 7:14:34 PM5/4/93
to

Yes, all you have to do is have a FORWARD declaration:

Procedure proc1(i: integer); forward;

procedure proc2(i: integer); forward;

procedure proc3(i: integer);
begin
case i of
1: proc1(i);
2: proc2(i);
3: proc3(i+1);
end;
end;

procedure proc1; { not necessary to repeat the parameter list }
begin
case i of
1: proc1(i+1);
2: proc2(i);
3: proc3(i);
end;
end;

procedure proc2;
begin
case i of
1: proc1(i);
2: proc2(i+1);
3: proc3(i);
end;
end;


Let's see...

proc3(1)-> proc1(1)-> proc1(2)-> proc2(2)-> proc2(3)-> proc3(3)-> proc3(4)

Let's see you do THAT in FORTRAN!

James P. Henley Jr.

Jeff Zeitlin

unread,
May 5, 1993, 4:39:00 PM5/5/93
to
MK::>I am stuck in a situation where I have three procedures which call each ot
::>However, there is no was to arrange them so that all are defined when call
::>thanks to Pascal's Top-Bottom design. Is there a way I can force a proced
::>to be recognized by a procedure preceeding it??

MK::>I don't read comp.lang.pascal often, so could you respond by email?? Than

Mike, I have to post because my Usenet gateway strips header
information off the article, and you didn't include your address
in the body of your article.

Most Pascal implementations should allow for "forward"
declarations to handle just this problem. In the implementations
I've seen (Microsoft, Borland, and Metaware) you declare one or
more of the two or more procedures as

Procedure CallMeLater(Params : ParamTypes); Forward;

then declare the remaining functions as though CallMeLater had
already been defined, then, last of all, put in the actual
definition of the forward-declared procedure, with the header

Procedure CallMeLater;

(without the parameter block. MS and Borland blow up if you
include parameters the second time).
==========================================================================
Jeff Zeitlin jeff.z...@execnet.com

* QMPro 1.01 * Vulcans do not approve of violence.

A.J. Brown

unread,
May 10, 1993, 12:04:10 PM5/10/93
to

Try a 'forward' declaration. I can't remember the exact syntax but it goes something like this....


Forward Fred (param list)

Procedure Ginger (....);

{some call to Fred}


Procedure Fred {no param list}


I hope !!


A.J....@uk.ac.newcastle

TERRY MICHAEL AUSPITZ

unread,
May 10, 1993, 9:47:52 PM5/10/93
to
A.J. Brown (A.J....@newcastle.ac.uk) wrote:


> Forward Fred (param list)

> Procedure Ginger (....);

> {some call to Fred}


> I hope !!


Almost. Try:
Procedure Fred(Param List); Forward;

Procedure Ginger(Param List);
Begin
{Code for Ginger};
{Some call to Fred};
{More code for Ginger};
End;

Procedure Fred {No Param list, but I usually include it AS A COMMENT};

Good luck!
-Terry


--
_______________________________________________________________________________
_/ _/ _/_/_/ | __o Terry M. Auspitz at Lehigh University
_/ _/ _/ _/ | _ \ <,_ (tm...@lehigh.edu)
_/_/_/_/ _/ | (_)/ (_) Would anyone else share these opinions?

0 new messages