comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Elaboration_check For Instantiations
Date: 1997/10/24
Date: 1997-10-24T00:00:00+00:00	[thread overview]
Message-ID: <dewar.877698488@merv> (raw)
In-Reply-To: 1997Oct23.202211.24396@nosc.mil


Charles says

          PACKAGE Ginspec IS

             GENERIC
                Param : IN Integer;
             PROCEDURE Template;

             PROCEDURE Instantiation IS NEW Template (1);

          END Ginspec;

was legal in Ada 83. That is true, it is also legal in Ada 95. However
in either version of the language it must raise Program_Error at runtime.
Indeed GNAT will say:

     1.           PACKAGE Ginspec IS
     2.
     3.              GENERIC
     4.                 Param : IN Integer;
     5.              PROCEDURE Template;
     6.
     7.              PROCEDURE Instantiation IS NEW Template (1);
                     |
        >>> warning: cannot instantiate "Template" before body seen
        >>> warning: Program_Error will be raised at run time

     8.
     9.           END Ginspec;

Any Ada 83 compiler that executes this code without raising a Program_Error
exception is seriously broken, assuming you have set the options for full
runtime checking according to the RM.

No Ada 83 compiler I have worked with was broken in this respect.

As to why this "restriction" is here, the point is that the model of
generics is that the body must be available to the compiler at the
point of instantiation, or more accurately that at runtime, the body
must have been elaborated. 

Just think about it. When you instantiate, you logically create a copy
of the body, which is elaborated at the point of the instantiation. How
could you create and elaborate the body of the instantiation if you have
not yet elaborated the body of the generic itself.

For example, consider that initializations in the body of the generic may
call functions within the body of the same generic. If the body is not
around, how could these calls be made?





      parent reply	other threads:[~1997-10-24  0:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-23  0:00 Elaboration_check For Instantiations Charles H. Sampson
1997-10-23  0:00 ` Charles H. Sampson
1997-10-24  0:00   ` Tucker Taft
1997-10-24  0:00     ` Robert Dewar
1997-10-27  0:00       ` Charles H. Sampson
1997-10-27  0:00         ` Robert Dewar
1997-10-28  0:00           ` Charles H. Sampson
1997-10-28  0:00             ` Keith Thompson
1997-10-28  0:00               ` Charles H. Sampson
1997-10-29  0:00                 ` W. Wesley Groleau x4923
1997-10-29  0:00                   ` Tom Moran
1997-10-30  0:00                     ` Larry Kilgallen
1997-10-30  0:00                   ` Charles H. Sampson
     [not found]                   ` <345774b3.1434102@santaclara01.news.internex.net>
1997-10-30  0:00                     ` Charles H. Sampson
1997-10-29  0:00                 ` Robert Dewar
1997-10-29  0:00                   ` Charles H. Sampson
1997-10-29  0:00             ` Robert Dewar
1997-10-27  0:00     ` Charles H. Sampson
1997-10-27  0:00       ` Robert Dewar
1997-10-24  0:00 ` Robert Dewar [this message]
replies disabled

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