comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: derived types, constants and literals
Date: 24 Oct 94 16:05:11
Date: 1994-10-24T16:05:11+00:00	[thread overview]
Message-ID: <EACHUS.94Oct24160511@spectre.mitre.org> (raw)
In-Reply-To: leschkes@ferret.cig.mot.com's message of 24 Oct 94 16:34:40 GMT

In article <leschkes.783016480@ferret> leschkes@ferret.cig.mot.com (Scott Leschke) writes:

  > In Ada 83' constants of a type were not derived along with the
  > operations on that type.  For example:

  > package Test1 is
  >   type X is range 0..100;
  >   Null_Val : constant X := 0;
  >    procedure DoIt(Val : in X := Null_Val);
  > end Test1;

  > with Test1;
  > package Test2 is
  >   type Y is new Test1.X;
  >   B : constant Y := Null_Val;  -- doesn't compile
  > -- B : constant Y := Y(Test1.Null_Val);  -- compiles
  > end Test2;

   Did you think to try:

      function Null_Val returns X?

   Now B: constant Y := Null_Val; works just fine in both Ada 83 and
Ada 9X.  In Ada a lot of things that you normally think of as
constants (character literals and enumeration literals for example)
are defined as functions to get the appropriate behavior.  Just accept
the fact that an Ada constant is not a C constant or a FORTRAN
constant, and an Ada function is different from a C function or a
FORTRAN function and you won't have a problem.  (Ada constants don't
even have to be statically sized, let alone have static values,
whereas some Ada functions are defined to be static.)
        

  > It always struck me as odd that in Ada83, constants of a type could
  > not be derived and overridden just like operations were.  Since theyb
  > aren't, one of two possibilities exists for procedure Test2.DoIt.

  > Either it is derived as:
  >   procedure DoIt(Val : Y := Y(Test1.Null_Val));...

     Got it the first time.  In some cases this conversion may be more
than just a view conversion.

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...



       reply	other threads:[~1994-10-24 16:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <leschkes.783016480@ferret>
1994-10-24 16:05 ` Robert I. Eachus [this message]
1994-10-24 21:05 ` derived types, constants and literals Tucker Taft
replies disabled

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