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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,810843c254562cd8 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Embedded systems programmers worldwide earn failing grades in C Date: Mon, 25 Jan 2010 15:22:24 -0800 Organization: None to speak of Message-ID: References: <3aadd38d-0496-4f61-ba82-d0e1f0c983d2@a32g2000yqm.googlegroups.com> <7roqb2Fas8U1@mid.individual.net> <5pppl5lm5h1eerr6aesru2n9poois8vesc@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 25 Jan 2010 23:25:52 +0000 (UTC) Injection-Info: news.motzarella.org; posting-host="f6Njqws0KA42eUrAB2+3Cw"; logging-data="4787"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+h+eHwSz37ja1OE4NiHJiR" User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:7qrWEtKVUC6dALAlAgeb5HV+B90= sha1:oenzMIE/Hdgp2YX92n2LTzW/b/Q= Xref: g2news1.google.com comp.lang.ada:8822 Date: 2010-01-25T15:22:24-08:00 List-Id: Brian Drummond writes: [...] > Q: Which of the following is the most portable way to declare an Ada > (which has no preprocessor) constant for the number of seconds in a > (non-leap) calendar year? > > (a) Seconds_Per_Year : constant natural := 60 * 60 * 24 * 365; > (b) no preprocessor traps from textual substitution, so no ( ) subtleties > (c) literals of type Universal Integer, so no explicit size qualifiers > (d) all of the above are true, why make it more complex than (a)? (b), (c), and (d) aren't really choices. But the correct answer is (e) none of the above. Since Natural'Last isn't required to be bigger than 32767, and 60 * 60 * 24 * 365 is 31536000, your declaration of Seconds_Per_Year is illegal on some systems. (Where it's legal, you probably won't get a warning from the compiler, which is a pity.) A better answer IMHO is: Seconds_Per_Year : constant := 60 * 60 * 24 * 365; Why specify subtype Natural if you don't need to? As I recall, the corresponding C question presented a similar issue. Ada does have a better solution, but only if you use it. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"