From: rriehle@itu.edu
Subject: Re: Can .ads be compiled alone?
Date: Sat, 15 Nov 2014 04:54:51 -0800 (PST)
Date: 2014-11-15T04:54:51-08:00 [thread overview]
Message-ID: <bac208e0-0f64-4f99-b279-7696544a4d9b@googlegroups.com> (raw)
In-Reply-To: <520f8f3d-b345-4ef8-ac41-ead78edde92a@googlegroups.com>
On Thursday, November 6, 2014 9:21:38 PM UTC-8, moixa wrote:
> Newbie question.
>
> I have only two files, machinery_1_3.ads [1] and machinery_1_3.adb [2], in some directory, when I `gnat compile machinery_1_3.ads`, it told me compile error, (but no further information).
>
> A stackoverflow post[3] said that it's a good practice to separate compile the spec and the body, so, why I cannot compile my .ads?
>
> ---------------------------
>
> [3] http://stackoverflow.com/questions/9921794/error-when-compiling-spec-files
>
> ---------------------------
>
> [1] machinery_1_3.ads
> package Machinery_1_3 is -- 1 Package specification; requires body
> type Machine is private; -- 2 Specifies the visible part of the data type;
> procedure Turn_On (M : in out Machine); -- 3 procedure specification
> procedure Turn_Off (M : in out Machine); -- 4 procedure specification
> function Is_On (M : in Machine) return Boolean; -- 5 function specification
> private -- 6 private part hidden from a client of contract
> type Machine is record -- 7 full definition of the publicly declared type
> Turned_On : Boolean := False; -- 8 component of the type; OOP attribute
> end record; -- 9 scope terminator for the component
> end Machinery_1_3; -- 10 scope terminator for the specification
>
> ---------------------------
>
> [2] machinery_1_3.adb
> package body Machinery_1_3 is -- 1 Package body; implements specification declarations
> procedure Turn_On (M : in out Machine) is -- 2 Repeat procedure specification; compiler checks this
> begin -- 3 Starts algorithmic section of procedure
> M.Turned_ON := True; -- 4 Simple assignment statement of boolean value
> end Turn_On; -- 5 Procedure scope terminator is required
> procedure Turn_Off (M : in out Machine) is -- 6 Must match profile in specification
> begin -- 7 Algorithms between begin and end
> M.Turned_On := False; -- 8 M.Turned called dot notation
> end Turn_Off; -- 9 Name is optional but end is required
> function Is_On (M : in Machine) return Boolean is -- 10 In mode is like a constant; it may
> begin -- 11 not be on left side of assignment
> return M.Turned_On; -- 12 return statement required of every function
> end Is_On; -- 13 Scope terminator for function
> end Machinery_1_3; -- 14 End of all declarations for this package
================================================================
The code you just posted is directly copied from Ada Distilled. The specification will compile just fine since it is only a specification. You must compile the specification before the body. They should be compiled separately.
Richard Riehle, PhD (Author of Ada Distilled)
next prev parent reply other threads:[~2014-11-15 12:54 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-07 5:21 Can .ads be compiled alone? moixa
2014-11-07 6:09 ` Jeffrey Carter
2014-11-07 17:26 ` Robert A Duff
2014-11-07 17:41 ` Jeffrey Carter
2014-11-07 6:20 ` J-P. Rosen
2014-11-07 7:48 ` Chris Moore
2014-11-07 14:54 ` Tero Koskinen
2014-11-07 15:49 ` Björn Lundin
2014-11-07 16:29 ` G.B.
2014-11-08 13:01 ` moixa
2014-11-08 14:55 ` G.B.
2014-11-07 16:29 ` G.B.
2014-11-07 16:44 ` Adam Beneschan
2014-11-07 17:14 ` Shark8
2014-11-08 21:31 ` Chris Moore
2014-11-07 16:50 ` Adam Beneschan
2014-11-07 17:14 ` Robert A Duff
2014-11-08 2:01 ` Randy Brukardt
2014-11-15 12:54 ` rriehle [this message]
2014-11-15 19:17 ` Robert A Duff
2014-11-15 19:19 ` Robert A Duff
2014-11-17 15:52 ` Adam Beneschan
2014-11-17 0:07 ` rriehle
2014-11-17 6:50 ` Simon Wright
2014-11-24 3:16 ` rriehle
2014-11-24 6:34 ` 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