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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!feeder.erje.net!eu.feeder.erje.net!bloom-beacon.mit.edu!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Multiple procedures in the same adb file? Date: Sun, 11 Jan 2015 14:51:24 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <5fc3a42d-f922-4e34-ab30-59613b980fb6@googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls7.std.com 1421005891 662 192.74.137.71 (11 Jan 2015 19:51:31 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 11 Jan 2015 19:51:31 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:WKEw6ZEdDnZYXGubPK0TYN9klcc= Xref: news.eternal-september.org comp.lang.ada:24536 Date: 2015-01-11T14:51:24-05:00 List-Id: 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