[comp.lang.ada] Defered Constants in Ada

defaria@hpclapd.HP.COM (Andy DeFaria) (09/13/90)

I have been trying to  use defered constants in  Ada and I have  been  have
some problems.  Everything  seems to be   OK  if the   type of the  defered
constant is local but if the type is imported then  the compiler issues the
error message that follows:

----HP Ada/800    A.04.35------------------------------------------------------
Source file   : /tmp/note.ads
In Ada library: /tmp/adalib                        Next message at line:     18
-------------------------------------------------------------------------------
          
          
        1 package PACKAGE_ONE is
        2 
        3    type EXPORTED_TYPE is private;
        4    
        5 private
        6    type EXPORTED_TYPE is new STANDARD.INTEGER;
        7    
        8 end PACKAGE_ONE;
        9 
       10 with UNCHECKED_CONVERSION;
       11 with PACKAGE_ONE;
       12 
       13 package PACKAGE_TWO is
       14 
       15    type LOCAL_TYPE is private;
       16 
       17    DEFFERED_CONSTANT_1 : constant LOCAL_TYPE;
       18    DEFFERED_CONSTANT_2 : constant PACKAGE_ONE.EXPORTED_TYPE;
             <--------------------------1---------------------------> 
 1   **SEM 3018 A constant must be initialised - RM 3.2.1 (2).
       19    
       20 private
       21    function CONVERT is new UNCHECKED_CONVERSION
       22       (SOURCE => INTEGER, TARGET => PACKAGE_ONE.EXPORTED_TYPE);
       23        
       24    type LOCAL_TYPE is new STANDARD.INTEGER;
       25    
       26    DEFFERED_CONSTANT_1 : constant LOCAL_TYPE
       27       := 0;
       28    DEFFERED_CONSTANT_2 : constant PACKAGE_ONE.EXPORTED_TYPE
       29       := CONVERT (0);
       30                                                
       31 end PACKAGE_TWO;

           One error detected. No warning issued.  Compilation failed.

Faulty line is: 
-------------------------------------------------------------------------------
   **:18            
 One error detected. No warning issued.  Compilation failed.


The   real     question     is   why  is    DEFFERED_CONSTANT_1  OK   while
DEFFERED_CONSTANT_2 wrong?

defaria@hpclapd.HP.COM (Andy DeFaria) (09/14/90)

>/ hpclapd:comp.lang.ada / defaria@hpclapd.HP.COM (Andy DeFaria) /  2:00 pm  Sep 12, 1990 /

>I have been trying to  use defered constants in  Ada and I have  been  have
>some problems.  Everything  seems to be   OK  if the   type of the  defered
>constant is local but if the type is imported then  the compiler issues the
>error message that follows:

Thanks for the email responses to this question.  It turns out that this is
explicitly forbidden by the Ada LRM 7.4 (4)  with states that the type mark
for the defered constant must but declared in the same package.

Stupid me!  I know RTFM, RTFM, RTFM....

stt@inmet.inmet.com (09/14/90)

Re: Deferred Constants in Ada

Quoting from RM 7.4(4):

   "... a deferred constant declaration and the declaration of
the corresponding private type must both be declarative items
of the visible part of the same package."

It is interesting that this limitation is not mentioned
anywhere in the subsection devoted to Deferred Constants, but
only in the introduction to the section on
private types and deferred constants.

S. Tucker Taft
Intermetrics, Inc.
Cambridge, MA  02138

arra@inmet.UUCP (Arra Avakian) (09/14/90)

In article <920029@hpclapd.HP.COM> defaria@hpclapd.HP.COM (Andy DeFaria) writes:
>I have been trying to  use defered constants in  Ada and I have  been  have
>some problems.  Everything  seems to be   OK  if the   type of the  defered
>constant is local but if the type is imported then  the compiler issues the
>error message that follows:
(Example deleted to save space)

From LRM 7.4(4):  "...; a deferred constant declaration and the declaration of
the corresponding private type must both be declarative items of the visible
part of the same package."