comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Multiple procedures in the same adb file?
Date: Sun, 11 Jan 2015 14:51:24 -0500
Date: 2015-01-11T14:51:24-05:00	[thread overview]
Message-ID: <wcc1tn1m6yr.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 5fc3a42d-f922-4e34-ab30-59613b980fb6@googlegroups.com

John Smith <yoursurrogategod@gmail.com> 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

  parent reply	other threads:[~2015-01-11 19:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-11 18:37 Multiple procedures in the same adb file? John Smith
2015-01-11 19:05 ` John Smith
2015-01-11 19:51 ` Robert A Duff [this message]
2015-01-11 20:38   ` John Smith
2015-01-11 21:02     ` Robert A Duff
2015-01-11 21:51       ` John Smith
2015-01-12  0:53         ` Robert A Duff
2015-01-12  0:55         ` Robert A Duff
2015-01-13  0:11       ` Randy Brukardt
2015-01-11 21:38   ` Niklas Holsti
2015-01-12  0:53     ` Robert A Duff
2015-01-12  9:01       ` J-P. Rosen
2015-01-12 14:57         ` Robert A Duff
2015-01-13  0:09           ` Randy Brukardt
2015-01-12  0:55     ` Robert A Duff
2015-01-11 20:04 ` Jeffrey Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox