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 X-Received: by 10.236.26.200 with SMTP id c48mr55046161yha.46.1416056092571; Sat, 15 Nov 2014 04:54:52 -0800 (PST) X-Received: by 10.50.112.137 with SMTP id iq9mr217066igb.1.1416056092454; Sat, 15 Nov 2014 04:54:52 -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!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!i13no1826968qae.0!news-out.google.com!c9ni14081igv.0!nntp.google.com!h15no642409igd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 15 Nov 2014 04:54:51 -0800 (PST) In-Reply-To: <520f8f3d-b345-4ef8-ac41-ead78edde92a@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:9:1100:e95:a998:ef15:f869:8c48; posting-account=XrU4OgoAAADEPkoULFhRQzFYU74OGc9X NNTP-Posting-Host: 2601:9:1100:e95:a998:ef15:f869:8c48 References: <520f8f3d-b345-4ef8-ac41-ead78edde92a@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Can .ads be compiled alone? From: rriehle@itu.edu Injection-Date: Sat, 15 Nov 2014 12:54:52 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 4535 X-Received-Body-CRC: 4111347824 Xref: news.eternal-september.org comp.lang.ada:23371 Date: 2014-11-15T04:54:51-08:00 List-Id: 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)