comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: Language Lawyers help on rep_specs
Date: 4 Jan 1995 14:40:50 GMT
Date: 1995-01-04T14:40:50+00:00	[thread overview]
Message-ID: <3eec1i$179s@watnews1.watson.ibm.com> (raw)
In-Reply-To: 393@hathor.CSS.GOV

In article <393@hathor.CSS.GOV>, jeffe@hathor.CSS.GOV (Jeff Etrick) writes: 

|> The LRM references are saying that my type Nuclear_Date_Times may not be
|> used in a record represenation clause due to the fact it is not a simple
|> static expression. Talking to the vendor about this issue I was told that the
|> INTEGER conversion is a function and functions are not allowed in simple
|> static expressions.
...
|>   subtype Full_Integer is INTEGER range -2**31..2**31 - 1;
|>
|>   HOURS_IN_DAY       : constant  := 24;
|>   MINUTES_IN_HOUR    : constant  := 60;
|>   MINUTES_IN_DAY     : constant  := HOURS_IN_DAY * MINUTES_IN_HOUR;
|>
|>   -- This type defines days from December 30, 1944 through December 31, 2099.
|>   type Dates is new Full_Integer range -1 .. 56_613;
...
|>   type Nuclear_Date_Times is new Full_Integer
|>     range (INTEGER (Dates'first) - 1) * MINUTES_IN_DAY
|>                 .. (INTEGER (Dates'last) * MINUTES_IN_DAY) - 1;

Type conversions may look like function calls, but they are not.  In any
event, RM95 4.9(9) specifically states that conversion of a static
expression (such as Dates'First or Dates'Last) to a static subtype (such
as Integer) is static.

You could have achieved the same effect more simply, however, by writing

   type Nuclear_Date_Times is
      range (Dates'First-1)*Minutes_In_Day .. Dates'Last*Minutes_In_Day-1;

(While the bounds in the range constraint of a derived-type declaration
must belong to the parent type, the bounds in an integer type declaration
can belong to any integer type, making the type conversion unnecessary.)

--
Norman H. Cohen    ncohen@watson.ibm.com



      parent reply	other threads:[~1995-01-04 14:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-01-03 12:49 Language Lawyers help on rep_specs Jeff Etrick
1995-01-03 14:50 ` Theodore E. Dennison
1995-01-03 16:30   ` Tucker Taft
1995-01-03 18:04   ` Robert Dewar
1995-01-03 18:07   ` Robert Dewar
1995-01-03 15:06 ` Robert Dewar
1995-01-04 14:40 ` Norman H. Cohen [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