From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.50.78.136 with SMTP id b8mr11105463igx.4.1421008697850; Sun, 11 Jan 2015 12:38:17 -0800 (PST) X-Received: by 10.140.28.11 with SMTP id 11mr1155qgy.21.1421008697694; Sun, 11 Jan 2015 12:38:17 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!h15no3464790igd.0!news-out.google.com!n9ni482qai.0!nntp.google.com!v8no324254qal.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 11 Jan 2015 12:38:17 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.138.174.211; posting-account=AvekzAoAAABj-TclKcOWQmXwA49MFPGX NNTP-Posting-Host: 50.138.174.211 References: <5fc3a42d-f922-4e34-ab30-59613b980fb6@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Multiple procedures in the same adb file? From: John Smith Injection-Date: Sun, 11 Jan 2015 20:38:17 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:24538 Date: 2015-01-11T12:38:17-08:00 List-Id: Hello Bob, Thanks, that was really helpful. I got it to work by making the appropriate *.ads and *.adb files. I also had it working as a nested function. It seems a tad tedious at first, but it does make sense. Heck, even C/C++ recommends a similar approach. You want to separate the declaration from the implementation. On Sunday, January 11, 2015 at 2:51:32 PM UTC-5, Robert A Duff wrote: > John Smith writes: > > > I have a question, what if I want multiple procedures in the same adb > > file, can that be done? ... > > The simplest thing is to have a single procedure that is your main > procedure, and everything else in packages or generic packages. > The main procedure goes in one file, and each package spec and each > package body in a separate file. The naming convention is x.ads for > specs and x.adb for bodies, where x is the name of the compilation_unit > (i.e. the package spec or body or procedure body). > > You don't have to do that. There are ways to use different naming > conventions, put multiple compilation units in one files, etc, > but they are a nuisance. Look up gnatchop, pragma Source_File_Name, > and project files if you really want to do it differently than > the standard GNAT way. > > The main procedure doesn't need a spec, but it can have one. > It is unwise to have procedures outside of packages (other than the > main procedure, which Ada annoyingly doesn't allow to be in a package). > > For medium-to-large programs, use child packages. A single root package > (or small number of them), with everything else being child, grandchild, > and so on of the root(s). The main procedure can be a root, or can be a > child of your single root package. > > > =============================================================================== > > procedure a_test(A, B : Integer; C : out Integer) is > > begin > > C := A + B; > > end a_test; > > > > procedure test_procedure is > > output : Integer; > > begin > > a_test(23, 34, output); > > end test_procedure; > > =============================================================================== > > Note that you could nest a_test inside test_procedure. > > It's a good idea to follow common style rules, such as calling those > A_Test and Test_Procedure. (But the file names should be in lower > case.) > > - Bob