From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?Q?Bj=c3=b6rn_Lundin?= Newsgroups: comp.lang.ada Subject: Re: Ok to assume type Duration is for more than one day? Date: Mon, 23 Jan 2017 14:32:57 +0100 Organization: A noiseless patient Spider Message-ID: References: <52d00223-69b9-4a5c-a2e0-aaa906d9b200@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 23 Jan 2017 13:31:14 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="1780120e050c00f6f0a51cff6360d3a2"; logging-data="22873"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jrtX65fm6m8rUmUNJSKFG" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 In-Reply-To: Cancel-Lock: sha1:laXLE2FN3Psq7CyN2U19tbxuSQc= Xref: news.eternal-september.org comp.lang.ada:33133 Date: 2017-01-23T14:32:57+01:00 List-Id: 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