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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2bcab3f121e1e3a7 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.22.198 with SMTP id g6mr2406458pbf.29.1316530946454; Tue, 20 Sep 2011 08:02:26 -0700 (PDT) Path: lh7ni1183pbb.0!nntp.google.com!news1.google.com!postnews.google.com!cd4g2000vbb.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Optional body for nested generic Date: Tue, 20 Sep 2011 08:00:58 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1316530946 30879 127.0.0.1 (20 Sep 2011 15:02:26 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 20 Sep 2011 15:02:26 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: cd4g2000vbb.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: news1.google.com comp.lang.ada:18048 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-09-20T08:00:58-07:00 List-Id: On Sep 20, 5:48=A0am, Simon Wright wrote: > I was surprised to find that GNAT makes it optional to have a body for a ^^^^ I believe you misspelled "Ada". > nested generic package (in the code below, gpack1 has an empty body, > gpack2 doesn't have a body at all). > > package Pack is > =A0 =A0pragma Elaborate_Body; > =A0 =A0generic > =A0 =A0package Gpack1 is > =A0 =A0 =A0 procedure Proc; > =A0 =A0 =A0 pragma Import (C, Proc, "proc"); > =A0 =A0end Gpack1; > =A0 =A0generic > =A0 =A0package Gpack2 is > =A0 =A0 =A0 procedure Proc; > =A0 =A0 =A0 pragma Import (C, Proc, "proc"); > =A0 =A0end Gpack2; > end Pack; > > package body Pack is > =A0 =A0package body Gpack1 is > =A0 =A0end Gpack1; > end Pack; > > I suppose that the reasoning for disallowing unrequired bodies (roughly, > making it impossible to obsolete the ada library by adding/removing > something with no other impact) only applies at library level, where > there's a correspondence to a file? The rule indeed applies only to library packages (including generic packages); it's in RM 7.2(4). Since it's a language rule and not a GNAT rule, it doesn't have anything to do wtih "correspondence to a file"; however, since any compiler *allows* library package specs and bodies to be processed in different runs of the compiler (even if it doesn't require this), allowing a package body that isn't needed can lead to confusion (if, say, a package spec is changed from one that requires a body to one that doesn't---what happens to the body that was previously compiled?). See the Ada 95 Rationale, 10.4: "In Ada 83, if a package does not require a body, but has one nevertheless (perhaps to do some initialization), its body can become out-of-date, and be silently omitted form a subsequent build of an executable program. This can lead to mysterious run-time failures...". This reasoning doesn't apply in non-library package cases. -- Adam