comp.lang.ada
 help / color / mirror / Atom feed
From: "Björn Lundin" <b.f.lundin@gmail.com>
Subject: Re: Ok to assume type Duration is for more than one day?
Date: Mon, 23 Jan 2017 14:32:57 +0100
Date: 2017-01-23T14:32:57+01:00	[thread overview]
Message-ID: <o650j2$map$1@dont-email.me> (raw)
In-Reply-To: <o64f5v$h65$1@dont-email.me>

On 2017-01-23 09:35, G.B. wrote:
> On 22.01.17 12:37, reinkor wrote:
>> Does this mean that I take a considerable risk if I assume "Duration"
>> can represent more than one day?
> 
> Assess the risk using a compile time check. For example,
> 
>     Seconds_in_Day : constant := 24*60*60;
>     Minimum_Duration : constant := 100.0*Seconds_In_Day;
> 
>     procedure Check_Duration_More_Than_One_Day is
>     begin
>         case Standard.Boolean'(True) is
>            when Duration'Last < Minimum_Duration => null;
>            when True => null;
>         end case;
>     end Check_Duration_More_Than_One_Day;
> 
> Your implementation of Ada will reject the program at compile time
> if
>   Duration'Last < Minimum_Duration
> is True because choice values must not occur more than once
> in a case statement.
> 

or something like
 pragma Compile_Time_Error(Duration'Last > 100 * 86_400.0, "To large");

if Duration'Last > 100 * 86_400.0 you get a compile error
with the string "To large"
-- 
--
Björn


  parent reply	other threads:[~2017-01-23 13:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-22 11:37 Ok to assume type Duration is for more than one day? reinkor
2017-01-22 12:28 ` Jeffrey R. Carter
2017-01-23 20:47   ` Randy Brukardt
2017-01-22 16:39 ` AdaMagica
2017-01-23  8:35 ` G.B.
2017-01-23  8:43   ` G.B.
2017-01-23 13:32   ` Björn Lundin [this message]
2017-01-23 13:53     ` G.B.
2017-01-23 14:32       ` Björn Lundin
replies disabled

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