comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Optional body for nested generic
Date: Tue, 20 Sep 2011 11:15:31 -0400
Date: 2011-09-20T11:15:31-04:00	[thread overview]
Message-ID: <wcc8vpj8cto.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: m262kn2xcf.fsf@pushface.org

Simon Wright <simon@pushface.org> writes:

> I was surprised to find that GNAT makes it optional to have a body for a
> nested generic package (in the code below, gpack1 has an empty body,
> gpack2 doesn't have a body at all).
>
> package Pack is
>    pragma Elaborate_Body;
>    generic
>    package Gpack1 is
>       procedure Proc;
>       pragma Import (C, Proc, "proc");
>    end Gpack1;
>    generic
>    package Gpack2 is
>       procedure Proc;
>       pragma Import (C, Proc, "proc");
>    end Gpack2;
> end Pack;
>
> package body Pack is
>    package body Gpack1 is
>    end 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?

Yes, the reasoning only applies at library level.  That was the
thinking during the Ada 9X project.

However, I think the reasoning is bogus in the first place,
although I didn't realize it at the time.

Suppose there were no Elab_Body above.
If a file pack.adb (using the GNAT convention) exists,
then it should be compiled and linked in as part of the program.

If you delete pack.adb, then it should vanish.  The problem was
that Ada 83 compilers didn't do that -- they would link in the
obsolete object code for Pack body.

Likewise, if you created a new pack.adb, they wouldn't notice unless
you explicitly "compiled it into the program library".  Note that very
early versions of GNAT had this same "bug", thus proving that this
is an implementation issue, not a language issue.  (Those early
versions defined pack.adb to NOT exist in the program library unless
pack.ads required it for some reason, completely defeating the purpose.)
Long since fixed!

In a truly source-based program library, these problems just don't
exist.

- Bob



  parent reply	other threads:[~2011-09-20 15:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-20 12:48 Optional body for nested generic Simon Wright
2011-09-20 15:00 ` Adam Beneschan
2011-09-20 15:18   ` Simon Wright
2011-09-20 15:15 ` Robert A Duff [this message]
2011-09-21 15:01   ` Adam Beneschan
2011-09-22  3:43     ` Randy Brukardt
2011-09-22 14:28       ` Robert A Duff
2011-09-22 23:03         ` Randy Brukardt
2011-09-23  0:03           ` Adam Beneschan
replies disabled

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