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: 103376,2a34b7ad6c6a0774 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Efficiency of code generated by Ada compilers Date: Tue, 10 Aug 2010 08:39:36 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1jmwhfp.roo31ybayx2bN%csampson@inetworld.net> <87lj8ess7q.fsf@hugsarin.sparre-andersen.dk> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1281443990 21105 192.74.137.71 (10 Aug 2010 12:39:50 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 10 Aug 2010 12:39:50 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:Rnu1teGFjw656sCHHM4gSRg+mYk= Xref: g2news1.google.com comp.lang.ada:13055 Date: 2010-08-10T08:39:36-04:00 List-Id: Jacob Sparre Andersen writes: > Robert A Duff wrote: >> Jeffrey Carter writes: > >>> type T is range 0 .. 2 ** N - 1; >>> for T'Size use N; > >> Yes. And T'Size = N by default in Ada >= 95, so I would write: >> >> pragma Assert(T'Size = N); >> >> instead of the Size clause. > > But don't you loose the compile time error in case the compiler > cannot make T'Size = N? No. Compilers are required to make T'Size = N. See 13.3(54-55). The Assert is just a hint that we care about that fact. Suppose N = 32, and I make a mistake, and write: pragma Assert (T'Size = 33); GNAT will warn that this is False, which is what I want. (And in -gnatwe mode, that's an error.) If I instead wrote "for T'Size use 33;", the compiler will not catch the error, but will instead use a strange Size. That's why I don't like to use rep clauses to assert that the compiler chose the obviously-correct representation -- the compiler will complain if it's too small, but not if it's too big. Consider: type M is mod 32; -- Oops, I meant 2**32. for M'Size use 32; -- No error here. I've seen this bug in real code. - Bob