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 Path: g2news1.google.com!news2.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 11:01:10 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <8349c981-4dca-49dc-9189-8ea726234de3@f42g2000yqn.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: pcls6.std.com 1281452445 9191 192.74.137.71 (10 Aug 2010 15:00:45 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 10 Aug 2010 15:00:45 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:3jeJq5HQhICgTkyZsR4qnH7RPG8= Xref: g2news1.google.com comp.lang.ada:13071 Date: 2010-08-10T11:01:10-04:00 List-Id: Elias Salom�o Helou Neto writes: > does Ada allow me to do non range-checked access to arrays? Yes. Pragma Suppress can be used to turn off some or all run-time checks, locally or globally. As far as I know, all Ada compilers have some way to do the same thing via compiler options (command-line switches or whatever). >> Ada has generics which are roughly same as templates. Unlikely to C+ >> generics are contracted and not automatically instantiated. > > What exactly does it mean? Is it something like run-time > instantiation? No, Ada generics work the same way as C++ templates -- the typical implementation is that each instance gets a separate copy of the code; instantiation happens at compile time. There is no run-time instantiation. "Contracted" above means that if the instantiation obeys the contract, then you can't get any compilation errors in the body of the template. For example, the generic says it wants a type with certain operations, or with certain properties, and if the instance supplies such a type, all is well. "Not automatically instantiated" above means that each instantiation of a generic appears explicitly in the code, as a separate declaration. > I don't fully understand the code, but it does seem to be very > intuitive. What does > > type Real is digits <>; > > mean? Is "digits" a keyword of the language? Yes. To declare a floating-point type: type My_Float is digits 6; And the compiler will pick some hardware type with at least the requested precision. "My_Float'Digits" queries the precision. Or: type My_Float is digits 7 range 0.0 .. 1.0; If you ask for more digits than are supported, the compiler will complain. The "digits <>" notation means this is a generic formal type, and the instantiation should pass in an actual type that is some floating-point type. Different instantiations might pass different types with different 'Digits, and inside the generic you can query it. In other words, the "<>" means roughly "unknown". If you try to pass a non-floating-point type to Real, you will get a compile-time error. - Bob