siping@cathedral.cerc.wvu.wvnet.edu (Siping Liu) (09/15/90)
I am a beginer of ADA and I have a very simple question which my book didn't tell me how to do it. At the top level, can I have one procedure calling another procedure? My book (software engineering with ada by Grady Booch) says so but my compiler tells me "proc1" is not declared: procedure proc1 is begin .... end proc1; procedure proc2 is begin .... proc1; .... end proc2; Can you tell me what's wrong? Thank you for your help. siping@cerc.wvu.wvnet.edu
stt@inmet.inmet.com (09/15/90)
Re: calling one top-level procedure from another I am sure you will get a million responses on this one... You need a "with" clause: with proc1; procedure proc2 is ... Top-level compilation units (aka library units) are only visible in other compilation units if they are mentioned in a "with" clause. As Steven Jobs would put it, the Ada "with" clause is "insanely great." Without it, any module could call any other module with no indication. The "with" clause very neatly identifies all of the external references required by a library unit. S. Tucker Taft Intermetrics, Inc. Cambridge, MA 02138
mfeldman@seas.gwu.edu (Michael Feldman) (09/16/90)
In article <794@babcock.cerc.wvu.wvnet.edu> siping@cathedral.cerc.wvu.wvnet.edu (Siping Liu) writes: >I am a beginer of ADA and I have a very simple question ^^^ not to be fussy, but please spell it Ada, not ADA. >which my book didn't tell me how to do it. > >At the top level, can I have one procedure calling another >procedure? My book (software engineering with ada by Grady Booch) >says so but my compiler tells me "proc1" is not declared: It is OK, but since proc1 and proc2 are distinct compilation units, proc2 cannot "see" proc1 unless you make it visible with a context clause, i.e. a "with". I compiled and ran the following under 3 different compilers without any problems. Note that it makes no difference, in Ada, whether these two procedures are in distinct source files or in one file. Even if they are in the same file Proc1 is not visible to Proc2 without the "with". This is different from C, for example, where Proc1 would be visible if it preceded Proc2 in the source file. Not in Ada, though. with Text_IO; procedure Proc1 is begin Text_IO.Put_Line("Procedure 1 was called OK"); end Proc1; with Text_IO; with Proc1; -- NOTE THIS CONTEXT CLAUSE procedure Proc2 is begin Text_IO.Put_Line("Procedure 1 is being called here"); Proc1; end Proc2; --------------------------------------------------------------------------- Prof. Michael Feldman Department of Electrical Engineering and Computer Science The George Washington University Washington, DC 20052 202-994-5253 mfeldman@seas.gwu.edu ---------------------------------------------------------------------------